Shared IP resolves to site

Not sure if this has already been addressed in the forum, if so just point me in that direction.

Here’s my issue, if I type in the shared IP address for my server, it resolves to one of the sites sharing that IP. This seems wrong to me. How does it choose which site to bring up that is sharing that IP? Does it just simply bring up the first one in the list?

Either way, I should be able to choose where this IP resolves (like our site on this same server since we’re hosting the sites) when sent via a browser or it should simply pull up a default Interworx page. My other servers run Plesk and I know that’s what happens if you try to visit the shared IP address on them. You can’t pull up one of the sites that way.

Apache reads the conf files in alphabetical order, and also matches vhost blocks in alphabetical order. What this means is that when someone goes to a shared IP, Apache will see that the first virtualhost block is a match, and serve that site up. You can do something like this to trick Apache into making mysite.com the first vhost read:

cd /etc/httpd/conf.d
ln -s mysite.com.conf 000000.conf

And then restart Apache.

I tried that, reloaded httpd and it didn’t work. There has to be something else that could be done.

UPDATE:
I added a rewrite rule to my first conf file that checks for the IP and redirects to my other site. Seems to do the trick.

Redirect shared IP

RewriteCond %{HTTP_HOST} ^##.##.###.###$
RewriteRule ^(.*)$ http://www.domain.com$1 [R=301]

As root, type:

httpd -t -D DUMP_VHOSTS

Does Apache correctly report the right domain as the default vhost? It should look something like this:


192.168.1.200:80       is a NameVirtualHost
         default server zebra.com (/etc/httpd/conf.d/00000.conf:1)

If Apache does report the correct domain, then perhaps your browser is caching the old content. Try a shift+reload.

Socheat

Hello,

Maybe look at my thread here http://www.interworx.com/forums/showthread.php?t=1755

Here is how we use our default domain for every shared ip

Pascal

Thanks pascal, I’m using the method from your previous thread.

Does anyone know if this issue will be taken care of in IW 3.0?

And if not, if I make these changes will they be written over out when 3.0 comes out?

It won’t change in IW 3.0 (although it’s still a good idea). If you make the change, they will not be written over when 3.0 come sout.

Paul