Page 1 of 1
apache2 and virtual hosts
Posted: Tue Apr 01, 2008 5:43 am
by shiznatix
I am running apache 2 on our development server here in our office. For forever I had just 1 domain pointing to it but now I need to get another one setup and ready to do some extra bonanza stuff. I am trying to split everything into 2 different directories, /var/www/ for the 1st domain and the /var/www2/ for the 2nd domain. I am trying to use a virtual host to do this but its just not taking.
The first domain is tallinn.rakeback.com and the new one I am trying to get to point to /var/www2/ is uus.rakeback.com. I have this at the end of my httpd.conf file:
Code: Select all
<VirtualHost uus.rakeback.com>
ServerAdmin root@localhost
DocumentRoot /var/www2/html
ServerName uus.rakeback.com
ErrorLog logs/uus.rakeback.com-error_log
CustomLog logs/uus.rakeback.com-access_log common
</VirtualHost>
but this doesn't work when I go to the domain. if I change the domain to the * it throws every request into there so I at least know it works the problem is that the server does not seam to recognize that the domain that was requested was uus.rakeback.com. How can I fix this and get this to work properly?
Re: apache2 and virtual hosts
Posted: Tue Apr 01, 2008 5:53 am
by EverLearning
Did you try ServerAlias directive? I think something like this would work
Code: Select all
<VirtualHost *>
ServerAdmin root@localhost
DocumentRoot /var/www2/html
ServerAlias uus.rakeback.com
ErrorLog logs/uus.rakeback.com-error_log
CustomLog logs/uus.rakeback.com-access_log common
</VirtualHost>
Re: apache2 and virtual hosts
Posted: Tue Apr 01, 2008 6:05 am
by shiznatix
Well that does pretty much the same thing as mine was doing. I need tallinn.rakeback.com to go to /var/www/html and uus.rakeback.com to go to /var/www2/html and neither of those are working. The server does not seam to figure out what domain is being requested.
Re: apache2 and virtual hosts
Posted: Tue Apr 01, 2008 6:11 am
by EverLearning
Where do your requests end up?
"/var/www/html" or "/var/www2/html"?
I have same thing set up, various domain names leading to different directories on one server, but i'm currently still at work(sort of...) and don't have access to that httpd.conf file, so I can't exactly tell you how I managed it until I get home, which will be in a couple of hours.
Re: apache2 and virtual hosts
Posted: Tue Apr 01, 2008 6:21 am
by shiznatix
this sends everything to /var/www/html even if you go to the domain uus.rakeback.com. It just never get triggered.
Code: Select all
<VirtualHost uus.rakeback.com>
ServerAdmin root@localhost
DocumentRoot /var/www2/html
ServerAlias uus.rakeback.com
ErrorLog logs/uus.rakeback.com-error_log
CustomLog logs/uus.rakeback.com-access_log common
</VirtualHost>
This sends everything to /var/www2/html no matter what domain.
Code: Select all
<VirtualHost *>
ServerAdmin root@localhost
DocumentRoot /var/www2/html
ServerAlias uus.rakeback.com
ErrorLog logs/uus.rakeback.com-error_log
CustomLog logs/uus.rakeback.com-access_log common
</VirtualHost>
Edit: I have noticed that even though apache does not seam to understand that I am requesting different domains, my PHP sessions are not carried between the 2 so even though the same page loads, if I am logged in on 1 then that does not make me logged into the other. Not sure if that means anything but ya....
Re: apache2 and virtual hosts
Posted: Tue Apr 01, 2008 7:58 am
by EverLearning
I'm home. Looked up on my configuration, and its pretty much what you already did, and what I posted.
Do your have VirtalHost for tallinn.rakeback.com set up,and how does it look?
This should work. It's exactly like mine configuration, only with your values:
Code: Select all
<VirtualHost *>
ServerAdmin root@localhost
DocumentRoot /var/www/html
ServerAlias tallinn.rakeback.com
ErrorLog logs/tallinn.rakeback.com-error_log
CustomLog logs/tallinn.rakeback.com-access_log common
</VirtualHost>
<VirtualHost *>
ServerAdmin root@localhost
DocumentRoot /var/www2/html
ServerAlias uus.rakeback.com
ErrorLog logs/uus.rakeback.com-error_log
CustomLog logs/uus.rakeback.com-access_log common
</VirtualHost>
Is there any clue in apache logs?
Re: apache2 and virtual hosts
Posted: Tue Apr 01, 2008 8:11 am
by shiznatix
I don't have a virtual host setup for tallinn.rakeback.com since it was the only domain pointing to that server until today. I tried your example but it just throws both domains to whatever the first entry is.
I am not sure where to find my apache log file but I get no errors on httpd restart or anything so not sure.
Re: apache2 and virtual hosts
Posted: Tue Apr 01, 2008 8:18 am
by EverLearning
You need VirtualHost directives for both of them, when there are more than one. Try substituting ServerAlias with ServerName. Maybe that will work

Re: apache2 and virtual hosts
Posted: Wed Apr 02, 2008 2:51 am
by shiznatix
Oh Oh something different!
I tried this configuration:
Code: Select all
<VirtualHost tallinn.rakeback.com>
ServerAdmin root@localhost
DocumentRoot /var/www/html
ServerName tallinn.rakeback.com
ErrorLog logs/tallinn.rakeback.com-error_log
CustomLog logs/tallinn.rakeback.com-access_log common
</VirtualHost>
<VirtualHost uus.rakeback.com>
ServerAdmin root@localhost
DocumentRoot /var/www2/html
ServerName uus.rakeback.com
ErrorLog logs/uus.rakeback.com-error_log
CustomLog logs/uus.rakeback.com-access_log common
</VirtualHost>
and when I startup apache I get this error message:
Starting httpd: [Wed Apr 02 11:47:03 2008] [warn] VirtualHost tallinn.rakeback.com:0 overlaps with VirtualHost uus.rakeback.com:0, the first has precedence, perhaps you need a NameVirtualHost directive
Soooo I am thinking this is my problem. How do I fix this?
Re: apache2 and virtual hosts
Posted: Wed Apr 02, 2008 3:22 am
by EverLearning
Based on this link -
Name-based Virtual Host Support, this should work *fingers crossed*
Code: Select all
NameVirtualHost *
<VirtualHost *>
ServerAdmin root@localhost
DocumentRoot /var/www/html
ServerName tallinn.rakeback.com
ErrorLog logs/tallinn.rakeback.com-error_log
CustomLog logs/tallinn.rakeback.com-access_log common
</VirtualHost>
<VirtualHost *>
ServerAdmin root@localhost
DocumentRoot /var/www2/html
ServerName uus.rakeback.com
ErrorLog logs/uus.rakeback.com-error_log
CustomLog logs/uus.rakeback.com-access_log common
</VirtualHost>
Re: apache2 and virtual hosts
Posted: Wed Apr 02, 2008 5:46 am
by shiznatix
Hooray! It took a bit extra because with your config and with mod_ssl it forces you to be in https at all times. After I realized that under https everything was working properly I changed my config to this:
Code: Select all
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin root@localhost
DocumentRoot /var/www/html
ServerName tallinn.rakeback.com
ErrorLog logs/tallinn.rakeback.com-error_log
CustomLog logs/tallinn.rakeback.com-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin root@localhost
DocumentRoot /var/www2/html
ServerName uus.rakeback.com
ErrorLog logs/uus.rakeback.com-error_log
CustomLog logs/uus.rakeback.com-access_log common
</VirtualHost>
and everything works peachy perfect. Thanks a bunch for your help!
Re: apache2 and virtual hosts
Posted: Wed Apr 02, 2008 5:48 am
by EverLearning
No problemo
I also learned something new
