I have a local server at home running debian 8. I access this server with its ip address given from the router. Now I wanted to try to work with virtualhosts to make my server a bit better. I created two virtualhosts blog.com and mysite.com. But my problem is that they are both not working. Everytime I enter them in the browser nothing happens. I have already tried several solutions here on stack overflow or with google. Nothing helped.

Any advice?

What I have done:

First: I have set up two further directories besides the default one for the sites and changed the directory of the default.

1) for blog.com: /var/www/blog.com/html

2) for mysite.com: /var/www/mysite.com/html

3) changed the default: /var/www/html to /var/www/default/html

Second: Then I created in every html folder a index.html file

Third: I created two further .conf files in the /etc/apache2/sites-available directory and changed the default.conf DocumentRoot


<VirtualHost *:80>
    ServerName blog.com
    ServerAlias www.blog.com
    ServerAdmin info@blog.com
    DocumentRoot /var/www/blog.com/html/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


<VirtualHost *:80>
    ServerName mysite.com
    ServerAlias www.mysite.com
    ServerAdmin info@mysite.com
    DocumentRoot /var/www/mysite.com/html/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Changed default.conf DocumentRoot to:


<VirtualHost *:80>
    ServerAdmin info@default.com
    DocumentRoot /var/www/default/html/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Fourth: Enabled my two new sites

sudo a2ensite blog.com.conf

sudo a2ensite mysite.com.conf

Fifth: I restarted apache

sudo service apache2 restart

Also did reload

sudo service apache2 reload

sudo /etc/init.d/apache2 restart

Sixth: I edited my hosts file localhost
ip blog.com
ip mysite.com
  • 1
    What error do you get? What does ip mean in hosts file? Can you ping blog.com and mysite.com?
    – Diamond
    Jan 4 '16 at 22:22
  • I don't get any error. Even in the error log. ip is the server ip address given from the router. The default site works perfectly with the ip. mysite.com and blog.com are unknown host when I ping them
    – Megaetron
    Jan 4 '16 at 22:33
  • 1
    Well that's the problem. I guess you are using your router as your dns server and it has no idea of the blog.com and mysite.com. In which hosts file you are adding the ips? Try adding them in the computer you are testing from and make sure it resolves to the server ip address.
    – Diamond
    Jan 4 '16 at 22:41
  • I added the ips in the hosts file of my server. Ok let me test that.
    – Megaetron
    Jan 4 '16 at 22:48
  • 1
    Glad that it helped. May be you should take a little time to read about name based virtual hosting and dns.
    – Diamond
    Jan 4 '16 at 23:18

For the name based virtual hosting to work, you have to make sure that the hostnames you are trying to access the sites, resolve to the server ip address. That means, in your case, blog.com and mysite.com should resolve to the server local ip address. These are supposed to be done by configuring nameservers accordingly.

Another way to achieve this locally is to add the entries to the local pc's hosts file so that it resolves correctly. As you have put the entries in your servers hosts file, your pc is not aware of it and can't resolve the names and no request for the sites are reaching anywhere.

Have a look at Name-based Virtual Hosting and Microsoft TCP/IP Host Name Resolution Order


Virtualhost configuration seems to be ok. The problem here is that your computer don't know who is blog.com and mysite.com.

You need to make the configuration that you did in hosts server's file, but in your own computer:

  • If you use Linux, you can do it the same way that you did in server, editing /etc/hosts file.
  • If you use Windows, you can do it editing C:\Windows\System32\Drivers\etc\hosts file

This make that the computer will check first in hosts file if it have some record for blog.com or mysite.com resolution, instead of looking it directly in the primary dns configured on it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.