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.

We have a production erp server that has heretofore only been accessible from the LAN. We now have a requirement that parts of it be accessible from outside.

We don't run DNS internally, so all access has just been with 192.168.x.x. The few exceptions for accessing from outside the LAN have been done with whitelisting a few IPs in the router's ACL, and adding a static route to forward traffic hitting the router's static WAN IP.

Right now, I've set up a domain name to hit another of our IPs. There is another static route in the router config to forward traffic for that IP to the same server. I've basically just created another way to hit the same server on 80/443.

What I would like to do now is set up a virtualhost config so that traffic coming in via the new domain will hit a particular folder... domain.com/public for example.

What I'm unsure of, is what, if any, affect this may have on the existing no-virtualhost setup.

TL;DR

If I set up a virtualhost config to point domain-based traffic to a specific folder, do I have to be explicit (set up another virtualhost) about non-domain-based traffic being able to hit the root as it already does now?

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

If the domain virtual host is going to use the same IP and Port as the main server, you will need to add a default virtualhost.

You will need to list the default virtual host first in the config file to ensure that it is used when the server is accessed by IP address.

See the 'Main host goes away' box here http://httpd.apache.org/docs/2.4/vhosts/name-based.html#using

share|improve this answer
    
Thanks for the link. Looks like that's the info I need. Additionally, and this may actually be a different question entirely, but is all of this virtualhost config just as pertinent if the server itself does not have a public IP?, but rather a router forwards requests to a LAN IP? –  JoshP Jun 17 '13 at 14:11
    
Yes it is - Apache doesn't care or know if the configured IPs are public or private. If the virtual host and main server are going to listen on the same IP and port, you will need a default virtual host. –  Vortura Jun 17 '13 at 14:17
    
super, thanks :) –  JoshP Jun 17 '13 at 14:22
add comment

Apache does its VirtualHost "decisions" based on where the entries are located in the configuration file. You'll need both entries (one for the VirtualHost and another for *:80/443) and put the VirtualHost one before the catch-all statement.

share|improve this answer
add comment

Any domains that resolve to your web server's IP address but are not explicitly listed in a virtual host stanza will be given the content of the first-listed virtual host. So, if you have stanzas for "a.com", "b.com", and "c.com", in that order, and the domain "d.com" resolves to the same IP address, you will get the web pages for the "a.com" domain.

share|improve this answer
    
If I'm reading yours and @Nathan's, answers correctly, you seem to be disagreeing on where the catch-all goes. Am I reading that correctly? –  JoshP Jun 17 '13 at 13:47
    
You're reading that correctly - in my experience, which may or may not hold true for all versions of Apache, the default, or "catch-all", virtual host ends up being the first one. –  John Jun 17 '13 at 14:18
    
thanks for the clarification –  JoshP Jun 17 '13 at 14:21
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.