I'm running apache on my local machine and I'm trying to create a subdomain, but it's not working. Here is what I have (stripped down):
<VirtualHost *:80>
DocumentRoot /var/www/one
ServerName one.localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/two
ServerName two.localhost
</VirtualHost>
I recently added one
. The two
entry has been around for a while, and it still works fine (displays the webpage when I go to two.localhost
). In fact, I copied the entire two.localhost
entry and simply changed two
to one
, but it's not working. I have tried each of the following:
* `apachectl -k graceful`
* `apachectl -k restart`
* `/etc/init.d/apache2 restart`
* `/etc/init.d/apache2 stop && !#:0 start`
Apache will complain if /var/www/one
does not exist, so I know it's doing something, but when I visit one.localhost
in my browser, the browser complains that nothing is there. I put an index.html
file there and also tried going to one.localhost/index.html
directly, and the browser still won't fine it. This is very perplexing since the entry I copied from two.localhost
is exactly the same .. not only that, but if something were wrong I would expect to get a 500 rather than the browser not being able to find anything. The error_log
also has nothing extra.
Is 'one.localhost' in your
/etc/hosts
- Verify resolution withping one.localhost
Do you have a
NameVirtualHost *:80
directive also? You need that to tell Apache that "*:80" is a name-based virtual host, instead of an IP address-based virtual host. See the difference here: http://httpd.apache.org/docs/2.2/vhosts/name-based.htmlAlso, have you tried running
apachectl -t
to perform a syntax check on the config files?You can try to look at your server access log file. If you did not find any record that matches your source IP and requested URL, then you are not reaching your server using this subdomain..
One point you did not talk about is the DNS name resolution of
one.localhost
. You need either to define anA / CNAME
record in your DNS server to respond to resolve requests ofone.localhost
or at least you need to add a new entry in/etc/hosts
file on your client machine (C:\Windows\System32\drivers\etc\hosts
in Windows machines).If you are able to reach your server, then most probably it is a configuration issue. You need to look at the overall configuration not just a small part. Also, you may have some rewrite rules/.htaccess files, etc...