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

I have a server with vhosts conf that looks like this:

NameVirtualHost *:80

# My Virtual Hosts:
<VirtualHost *:80>
     ServerName domain

     DirectoryIndex index.php index.html
     DocumentRoot /var/www/domain/public

     # Custom log file locations
     LogLevel warn

     ErrorLog /var/www/domain/log/error_log
     CustomLog /var/www/domain/log/access_log combined

     <Directory "/var/www/dailysongfix/public">
         Options Indexes FollowSymLinks
         AllowOverride All
         Order allow,deny
         Allow from all

A typical vhost conf right? Well I also need to develop a few other sites on the server and these sites don't have domains hooked to them yet. How can I view them without a domain pointing at them? I am guessing maybe the IP address and a port, but not sure how to set that up.

share|improve this question
up vote 7 down vote accepted

If you're going to use named virtual hosts, you need to assign some name to the server. In your example, the host will be addressed by the name domain (from the ServerName domain directive). You can try to contact your server by IP address directly by doing something like but that won't cause Apache to trigger the named virtual host. To do this you will need to add something like this to your /etc/hosts file on the client:    domain

Then, you should be able to use http://domain/ in your browser. This sets up the mapping between name and IP address locally without having to mess with DNS.

The way this works is when the browser sends the HTTP request to the server, it includes whatever text it used after the // in the URL in a Host: header. Apache takes this text in the Host: header and matches it against ServerName values in each named virtual host. When it finds a match, it uses that as the server to process the rest of the request. Apache does not need to look up the mapping between the host name and IP address, which is why this works if you only change the client machine configuration.

share|improve this answer
...or setup the DNS server inside the LAN to do this. We use both settings in my job. – elcuco Jun 14 '09 at 20:20
I like this solution but I haven't been able to get it to work. I put my ip address and domain in /etc/hosts like "xx.xx.xx.xx". and then i created another vhost entry exactly like the one above in my question but for the new "". apache still serves the first vhost listed in my conf file when i go to xx.xx.xx.xx any idea why that would happen? – Tony Jun 14 '09 at 20:43
can you check your logs in /var/log/httpd/error_log (and perhaps the logs specified by you above)? It sounds like you have a default virtual host (your only current domain) which is being used to handle all requests due to a possible httpd.conf error :) – Andy Jun 14 '09 at 21:05
the apache log shows no problems and the logs above are empty because they haven't been accessed yet. i actually have 3 websites running that are all accessed fine. it seems like apache is never translating the IP to the domain name – Tony Jun 14 '09 at 22:18
Apache cannot look up the named virtual host if you access your web site by IP address only. You must access it by using its actual name (that matches ServerName), which is why you need to tell your browser (through /etc/hosts) how to map that name to the IP address of your server. – Greg Hewgill Jun 14 '09 at 22:30

Use "Alias" instead of VirtualHost, it should work out fine if your PHP applications don't require a fixed URL.

Edit: You can add the aliases to the config you pasted above, just add them before the container.

share|improve this answer

maybe not the best way to go but you always can do as follows:

  1. create dns entry * that points to ip of your server
  2. user ServerAlias in each vhost definition eg: ServerAlias

i know i know - it's not exactly what you asked for but i think can solve your problem.

alternativly if your vhosts have exactly the same configuration just put your webpages in /somewhere/{nameOfDomain} and then share /somewhere as another vhost. then you'll be able to access any paged by going to http://myVhost/{nameOfDomain}. this can cause some security risk if in vhosts you have some access rules [ which would be probably not included in 'another vhost' configuration ].

share|improve this answer

On any standard packaged apache will be setup for use via ip address. which basically doesnt have a virtual host

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.