Apache2 Name Based VirtualHosts all show the first site only...
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Apache2 Name Based VirtualHosts all show the first site only...
I am at a loss on this one,
I am trying to serve Name Based Virtualhosts on my Debian 6/Apache 2 server, but both sites only go to site1...it's as if site2 virtualhost doesn't even exist.
Have you enabled the 2nd vhost and reload apache? What gives:
Code:
apache2 -S
Also make sure you're spelling correctly the ServerName of the 2nd vhost, because if apache cannot find a vhost with that name, it defaults to the 1st one.
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server www.site1.com (/etc/apache2/sites-enabled/site1:1)
port 80 namevhost www.site1.com (/etc/apache2/sites-enabled/site1:1)
port 80 namevhost www.site2.com (/etc/apache2/sites-enabled/site2:1)
Syntax OK
The vhosts look fine. Are there any messages when apache starts, or any warnings in error_log?
Check /etc/apache2/conf.d/virtual.conf and see if you have a different definition of NameVirtualHost.
I had a very similar problem a few weeks ago. Everything was correct in the vhosts declarations. Server had been reloaded and restarted. Could see the changes had 'stuck'. Nothing in the logs and requests for the VHOST were going to the default every time. I was ripping out my hair after about 3 hours. I altered the logging options in /etc/apache2/apache2.conf to make sure the host header was coming in:
In the end I disabled the virtual host (a2dissite), renamed the vhost file, a2ensite'd it and restarted the server and it worked right away. Quite why I have never discovered. Not sure if it was a non repeatable bug, or just a plain old 'feature'.
The vhosts look fine. Are there any messages when apache starts, or any warnings in error_log?
Check /etc/apache2/conf.d/virtual.conf and see if you have a different definition of NameVirtualHost.
Also what happens if you disable the 1st vhost?
When I start apache, there is no error message. Nothing in the logs except something about a python version mismatch but announces it gets it from the directory anyway.
the file /etc/apache2/conf.d/virtual.conf did not exist on my system.
I disabled the 1st vhost and it defaulted to the second one for both sites, when i turned the first vhost back on, it defaulted back to vhost1.
Leslie_Jones:
Quote:
I had a very similar problem a few weeks ago. Everything was correct in the vhosts declarations. Server had been reloaded and restarted. Could see the changes had 'stuck'. Nothing in the logs and requests for the VHOST were going to the default every time. I was ripping out my hair after about 3 hours. I altered the logging options in /etc/apache2/apache2.conf to make sure the host header was coming in:
Code:
LogFormat "%v:%p %h %l %u %t \"%r\" \"%{host}i\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
In the end I disabled the virtual host (a2dissite), renamed the vhost file, a2ensite'd it and restarted the server and it worked right away. Quite why I have never discovered. Not sure if it was a non repeatable bug, or just a plain old 'feature'.
Not sure if that is any help at all.
I changed the Log format and renamed the vhost, but still no cigar.
Thank you both for your assistance.
Last edited by mtlhd; 09-22-2011 at 05:02 PM.
Reason: updating
I disabled the 1st vhost and it defaulted to the second one for both sites, when i turned the first vhost back on, it defaulted back to vhost1.
There should be a mismatch between the names used in ServerName and/or ServerAlias and the names used in /etc/hosts. Please double-check the spelling of those hostnames and use ping and host commands to see if there is any difference in the hostname resolution
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.