Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache VirtualHost slow lookup

I finally managed how to configure properly httpd.conf for my virtualhost needings. This is the relevant part of httpd.conf file

NameVirtualHost *:80  <VirtualHost *:80>   ServerName localhost   DocumentRoot /Applications/XAMPP/htdocs/ </VirtualHost>  <VirtualHost *:80>   ServerName test.local   DocumentRoot /Applications/XAMPP/htdocs/test/ </VirtualHost>  <VirtualHost *:80>   ServerName work.local   DocumentRoot /Applications/XAMPP/htdocs/work/ </VirtualHost> 

When I access anything on localhost (i.e. http://localhost/phpmyadmin) everything is very fast. Whenever I access test.local or work.local (or others I configured) it spends 10-15 seconds on lookup. The following requests are handled correctly and it's very fast but after a minute or so of inactivity, it has to lookup again.

This is my /etc/hosts file

127.0.0.1       localhost 255.255.255.255 broadcasthost #::1             localhost fe80::1%lo0     localhost  # Virtualhosts 127.0.0.1       test.local     work.local    yii.local 

How could I fix this annoying issue?

like image 587
Leonardo Rossi Avatar asked Sep 25 '11 17:09

Leonardo Rossi


2 Answers

Add your virtual hosts to the first line:

127.0.0.1       localhost test.local work.local yii.local 

And remove the last line.

That should do the trick. Your vhosts are now an alias for localhost. It's not a good idea to have the same IP-address in multiple lines. This just confuses the DNS-cache.

like image 99
Alexander Janssen Avatar answered Oct 05 '22 13:10

Alexander Janssen


For anyone who is using Chrome and still gets slow virtual host lookup, you need to change the virtual host name to something else than .local, eg. change test.local to test.dev.

Explanation and source here: http://bencrowder.net/blog/2012/10/slow-localhost-in-chrome/

like image 37
xdim222 Avatar answered Oct 05 '22 14:10

xdim222