0

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.

adrianTNT
  • 1,077
  • 6
  • 22
  • 43

2 Answers2

2

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.

David Schwartz
  • 31,449
  • 2
  • 55
  • 84
  • I did a `NameVirtualHost IP:port` then two `VirtualHost`; in first the address and ServerName is site.com; 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 01:09
  • If you do that, and anything is wrong with DNS when Apache starts up, Apache will [misconfigure itself](http://httpd.apache.org/docs/1.3/dns-caveats.html). – David Schwartz Nov 12 '11 at 01:14
  • Sorry, you mean it would be bad not to specify IP? Or all setup I mentioned? – adrianTNT Nov 12 '11 at 01: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 01:24
0

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;

gWaldo
  • 11,957
  • 8
  • 42
  • 69