Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can someone tell me what httpd.conf settings I need to acomplish this?

When in browser I access http://IP I want to show: /var/www/html/ And when I access http://domain I want to show /var/www/html/_domains/domain

But I don't know how the (or whatever option) should look like, the http://IP keeps showing the domains directory rather than the html root.

share|improve this question
up vote 2 down vote accepted

Use 'NameVirtualHost' on the IP address. Then, for the two individual configurations, use a VirtualHost that precisely matches the IP, and a ServerName specifying the server's name. For the access by IP address, the server name is the IP address.

share|improve this answer
I did a NameVirtualHost IP:port then two VirtualHost; in first the address and ServerName is; and in second, address and ServerName is the IP. It works but I am confused, I was expecting it to work cleaner without specifying exact IP, just by associating a domain to a folder, and all other requests go to document root, without mentioning any IP. Is that possible? – adrianTNT Nov 12 '11 at 1:09
If you do that, and anything is wrong with DNS when Apache starts up, Apache will misconfigure itself. – David Schwartz Nov 12 '11 at 1:14
Sorry, you mean it would be bad not to specify IP? Or all setup I mentioned? – adrianTNT Nov 12 '11 at 1:21
You would be relying on the server to use DNS to find the IP. If that failed for some reason, the server couldn't configure itself. – David Schwartz Nov 12 '11 at 1:24
Thank you for your help. – adrianTNT Nov 12 '11 at 10:47

If you are using nginx, I would say to have two server blocks, and give the IP-based one an arbitrary name but set the default keyword like so:

listen 80 default;

share|improve this answer

Your Answer


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.