LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 09-09-2011, 01:59 PM   #1
mtlhd
Member
 
Registered: Sep 2007
Location: Florida
Distribution: Raspbian, Debian, CentOS, Ubuntu
Posts: 131

Rep: Reputation: 18
Unhappy 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.

conf files:

ports.conf
Code:
NameVirtualHost *:80
Listen 80
sites-enabled/site1
Code:
<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        ServerName www.site1.com
        ServerAlias site1.com
        DocumentRoot /home/me/www/site1

        <Directory /home/me/www/site1/>
                Options -Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>

</VirtualHost>
sites-enabled/site2
Code:
<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        ServerName www.site2.com
        ServerAlias site2.com
        DocumentRoot /home/me/www/site2

        <Directory /home/me/www/site2/>
                Options -Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>

</VirtualHost>
What is wrong with that set up? I don't see anything that could be breaking down.

Thanks in advance.
 
Old 09-09-2011, 04:08 PM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

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.

Regards
 
Old 09-13-2011, 07:51 AM   #3
mtlhd
Member
 
Registered: Sep 2007
Location: Florida
Distribution: Raspbian, Debian, CentOS, Ubuntu
Posts: 131

Original Poster
Rep: Reputation: 18
Unhappy Apache2 still defaulting to first VirtualHost

Thank you for your reply,

Yea I did the command 'a2ensite' for both sites and reloaded apache2 each time. It still defaulted to first site.

When i tried the apache2 -S command I recieved
Code:
apache2: bad user name ${APACHE_RUN_USER}
The apache2.conf file said that should be set in envvars, so I checked that file. I found this:
Code:
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
So I checked /etc/passwd to make sure that user existed, and it did.
Code:
www-data:x:33:33:www-data:/var/www:/bin/sh
Not sure where to go from here.

Thanks again for your help.
 
Old 09-13-2011, 08:22 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

It should work. Anyway try this solution to set APACHE_RUN_USER, or use:
Code:
apache2ctl - S
Regards
 
Old 09-13-2011, 08:33 AM   #5
rahulchandrak
Member
 
Registered: Apr 2010
Posts: 33

Rep: Reputation: 2
You might consider making an entry of the second v-host URL to /etc/hosts file and restart your network and try it
 
Old 09-13-2011, 01:32 PM   #6
mtlhd
Member
 
Registered: Sep 2007
Location: Florida
Distribution: Raspbian, Debian, CentOS, Ubuntu
Posts: 131

Original Poster
Rep: Reputation: 18
still no good

Thanks again to all who have replied. I appreciate your assistance.

I statically set the user and group.

same result.

I also added the domains to my host file...
/etc/hosts.conf

Code:
127.0.0.1     site1.com
127.0.0.1     site2.com
still defaults to site 1.

I am using dyndns to point to my ip address for each site....could something be breaking down there?

GoDaddy->DynDNS->my server

It is set up that way for each site...
 
Old 09-13-2011, 05:08 PM   #7
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
I statically set the user and group.

same result.
Did you try to use apach2ctl instead of apache2?
Anyway you need to use /etc/hosts and not /etc/hosts.conf to define the 2 hosts like this:
Code:
127.0.0.1 site1.com www.site1.com 
127.0.0.1 site2.com www.site2.com
Also since you don't have a fixed IP, make sure that all hostnames (site1.com www.site1.com site2.com www.site2.com) resolve to your external IP.
 
Old 09-15-2011, 01:44 PM   #8
mtlhd
Member
 
Registered: Sep 2007
Location: Florida
Distribution: Raspbian, Debian, CentOS, Ubuntu
Posts: 131

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by bathory View Post
Did you try to use apach2ctl instead of apache2?
Anyway you need to use /etc/hosts and not /etc/hosts.conf to define the 2 hosts like this:
Code:
127.0.0.1 site1.com www.site1.com 
127.0.0.1 site2.com www.site2.com
Also since you don't have a fixed IP, make sure that all hostnames (site1.com www.site1.com site2.com www.site2.com) resolve to your external IP.
Sorry, I don't know why I added '.conf' to the end of that file name, it was /etc/hosts

my hosts file reads:
Code:
127.0.0.1       localhost
127.0.1.1       debian.woh.rr.com       debian
127.0.0.1       site1.com               www.site1.com
127.0.0.1       site2.com               www.site2.com
Tried apache2ctl to restart as well....still defaults to site 1 for both....what could possibly be wrong?

The hostname of the machine is debian, is that causing problems?

also - GoDaddy points to the DynDNS address, then DynDNS points to my external IP.

-Thanks

Last edited by mtlhd; 09-15-2011 at 01:46 PM.
 
Old 09-15-2011, 04:31 PM   #9
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
Tried apache2ctl to restart as well....still defaults to site 1 for both....what could possibly be wrong?

The hostname of the machine is debian, is that causing problems?
I don't think it's a dns problem, as both domains resolve to your apache IP. It's the apache vhost configuration that is wrong somewhere.
Did you try?
Code:
/usr/sbin/apache2ctl -S
to see what vhosts are enabled?
Or you can take a look at /etc/apache2/sites-enabled to see if there exist the needed symlinks:
Code:
ls -l /etc/apache2/sites-enabled
 
Old 09-15-2011, 06:58 PM   #10
mtlhd
Member
 
Registered: Sep 2007
Location: Florida
Distribution: Raspbian, Debian, CentOS, Ubuntu
Posts: 131

Original Poster
Rep: Reputation: 18
result from /usr/sbin/apache2ctl -S
Code:
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
result from ls -l /etc/apache2/sites-enabled
Code:
total 0
lrwxrwxrwx 1 root root 30 Sep 13 08:42 site1 -> ../sites-available/site1
lrwxrwxrwx 1 root root 29 Sep 13 08:42 site2 -> ../sites-available/site2
Thank you so much for your continued assistance on this issue.
 
Old 09-16-2011, 01:00 AM   #11
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

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?
 
Old 09-16-2011, 09:27 AM   #12
leslie_jones
Member
 
Registered: Sep 2011
Posts: 130

Rep: Reputation: Disabled
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.
 
Old 09-22-2011, 05:01 PM   #13
mtlhd
Member
 
Registered: Sep 2007
Location: Florida
Distribution: Raspbian, Debian, CentOS, Ubuntu
Posts: 131

Original Poster
Rep: Reputation: 18
still nothin

Bathory:
Quote:
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
 
Old 09-23-2011, 12:47 AM   #14
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
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
Code:
ping www.site2.com
host www.site2.com
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Apache2: How To Redirect Users To Mobile Or Normal Web Site Based On Device Using mod_rewrite LXer Syndicated Linux News 0 09-09-2011 01:30 PM
Apache2 SSL configuration issues - *:80 has no VirtualHosts keymaster Linux - Server 2 03-07-2009 01:59 PM
debian with apache2 configuration for many VirtualHosts scottley Linux - Server 0 09-19-2007 01:05 AM
Apache, IP based VirtualHosts and 400 error ipslave Linux - Server 2 06-06-2007 06:28 AM
apache2 error - namevirtualhost *:0 has no virtualhosts? tiger.woods Ubuntu 2 04-09-2007 10:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration