0

I'm trying to get two websites on the same server to use different IP addresses. I've set up a virtual IP and set up the the virtual host. I restarted the network after adding the interface, and restarted apache after adding the vhost.

However, the default IP address is still being resolved for the 2nd site. What am I doing wrong?


SERVER

CentOS release 6.3 (el6.x86_64 GNU/Linux)


IFCONFIG

eth0      Link encap:Ethernet  
          inet addr:12.34.567.89  Bcast:12.34.567.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1


eth0:1    Link encap:Ethernet 
          inet addr:12.34.567.90  Bcast:12.34.567.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

HTTP CONF

NameVirtualHost 12.34.567.89
NameVirtualHost 12.34.567.90

<VirtualHost 12.34.567.89>
    DocumentRoot  /var/www/html
    ServerName website1.com
</VirtualHost>

<VirtualHost 12.34.567.90>
    DocumentRoot /var/www/html
    ServerName website2.com
</VirtualHost>

PING

# ping website2.com
PING website2.com (12.34.567.89) 56(84) bytes of data.

If I browse 12.34.567.90, it points to the wrong website: website1.com instead of website2.com

Any help would be appreciated as I've been at this for weeks.

Note: Specific IP addresses have been simplified and non-related content removed.

4 Answers 4

4
# ping website2.com
PING website2.com (12.34.567.89) 56(84) bytes of data.

What the hostname is resolving to is not influenced by your Apache configuration but solely by the DNS records of your domains.

According to ping, website2.com is resolving to 12.34.567.89, but the only (and therefore default) vhost for 12.34.567.89 is website1.com, so you're landing on website1.

Therefore you should check if your DNS records are configured correctly.

2
  • omg... How could I miss this? I'm pretty sure this is the answer. Let me work the magic and I'll be right back.
    – Lakitu
    Mar 21, 2013 at 16:22
  • Alright, so it'll be a while til the DNS changes propagate, but I'm absolutely certain this is the issue. Will go ahead and rep you. Thanks. I feel pretty dumb right now -_-
    – Lakitu
    Mar 21, 2013 at 16:26
1

If you have separate IP addresses for the two servers, you shouldn't use NameVirtualHost. That directive is specifically for having more than one site on the same IP address. So remove those two directives.

Also, in the config you posted, both web sites have the same DocumentRoot, which means they would serve the same content. But maybe this is one of the things you obfuscated?

1
  • Woops. Premature post via enter key. I'll try removing the NameVirtualHost. In addition, the DocumentRoots must be the same as the CMS we use is set up for both sites to use a single installation.
    – Lakitu
    Mar 21, 2013 at 16:16
0

I think the NameVirtualHost directives are introducing name based virtual hosting, try removing them. Ensure you have a suitable listen directive

Listen 80

Looking at the documentation they also put the port in the virtualhost definition so try

Listen 80
<VirtualHost 12.34.567.89:80>
    DocumentRoot  /var/www/html
    ServerName website1.com
</VirtualHost>

<VirtualHost 12.34.567.90:80>
    DocumentRoot /var/www/html
    ServerName website2.com
</VirtualHost>
0

is apache listing on all IPs?

run RHEL / CentOS

netstat -ntlp |grep httpd 

or for Debian / Ubuntu

netstat -ntlp |grep apache2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .