Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
What happens if you put listen ipaddr:80 into the config and restart with the vhost config being an IP address? –  qweet Jul 11 '12 at 12:52
    
I tried putting in Listen for that IP address but after that it will fail to restart apache, error: (99)Cannot assign requested address: make_sock: could not bind to address xx.xxx.xx.xxx:80 no listening sockets available, shutting down –  Alex Jul 11 '12 at 13:29
1  
Since you mentioned it, do you have internal network IPs? If you have something changing the IP address on the packet before it gets to your server, then apache won't know what the "public" IP address was, it will only see the internal IP. –  DerfK Jul 11 '12 at 14:02
    
Is this public IP address configured directly at your server? –  Alex Jul 11 '12 at 14:17
    
Hi, I contacted the hosting provider and it is as @DerfK thought that the IP is just pointing (nat'd) to the server but the server doesn't know about it. They told us to use the internal virtual server IP and not the public IP. Thanks guys this is now resolved. –  Alex Jul 11 '12 at 15:17
show 1 more comment

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
add comment

Do you still have the welcome.conf that CentOS puts in the Apache conf directory?

There's no need for it once you start customising your Apache configuration and it acts as a default catch-all vhost.

share|improve this answer
    
Hi @Ladadada I tried removing the welcome.conf but all that does is showing the root of directory /var/www/sites that contains the folder example.com –  Alex Jul 11 '12 at 13:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.