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 have a domain which points to my IP address, now I want to do the following: if I access the server locally (localhost / 127.0.0.1) I want it to server the pages from default DocumentRoot. If I access the server using the domain name, it servers files from other directory.

I edited httpd.conf adding following lines:

<VirtualHost *:80>
   ServerAdmin webmaster@localhost
   DocumentRoot "C:/Xampp/htdocs/mydomain"
   ServerName mydomain.com
</VirtualHost>

unfortunately, it doesn't work as expected - it serves files from "C:/Xampp/htdocs/mydomain" even if I access the server via localhost.

How do I fix it?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Here is what you want:

http://httpd.apache.org/docs/1.3/vhosts/name-based.html

Now when a request arrives, the server will first check if it is using an IP address that matches the NameVirtualHost. If it is, then it will look at each section with a matching IP address and try to find one where the ServerName or ServerAlias matches the requested hostname. If it finds one, then it uses the configuration for that server. If no matching virtual host is found, then the first listed virtual host that matches the IP address will be used.

As a consequence, the first listed virtual host is the default virtual host. The DocumentRoot from the main server will never be used when an IP address matches the NameVirtualHost directive. If you would like to have a special configuration for requests that do not match any particular virtual host, simply put that configuration in a container and list it first in the configuration file.

share|improve this answer

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.