Apache IP based hosting solution shows apache test page and not the website

apache-2.2centos6virtualhost

I am trying to setup my virtual server to host websites based on IP.
Currently I am trying to only setup 1 website and using only 1 IP.

/etc/httpd/conf.d/example.com.conf file contents:

Listen 80
NameVirtualHost xx.xxx.xx.xxx:80

<VirtualHost xx.xxx.xx.xxx:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/sites/example.com/public
    ErrorLog /var/log/httpd/example.com/error.log
    CustomLog /var/log/httpd/example.com/access.log combined
</VirtualHost>

I removed "Listen" and "NameVirtualHost" from httpd.conf and only using them in my example.com.conf files.

The problem that I'm having is that the apache test page kicks in and not the website but once I change the IP to "*" it works:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/sites/example.com/public
    ErrorLog /var/log/httpd/example.com/error.log
    CustomLog /var/log/httpd/example.com/access.log combined
</VirtualHost>

Any ideas why is this happening?

UPDATE!!
The IP address that I am trying to use is not an internal network IP but an external (public) IP address. I have 3 public IP addresses pointing to this server.

Thanks,
Alex

Best Answer

Since you have a firewall or some other device changing the IP on the packet from a public IP to a private IP, you will need to use the private IP in Apache's configuration for the VirtualHost. Apache will only see the private IP, so it won't know what public IP was originally requested.

Related Topic