Virtual host with Apache2 on Debian lenny

Hi,

how to enable a virtual host with apache2 on debian lenny that will be access like this

http://mysites.mydomain.com/subdomain2

http://subdomain1.mydomain.com is working but when I tried to access subdomain2, it will returned display subdomain1, what am I missing? below is the subdomain2 host file that I enabled (a2ensite subdomain2)
I also disabled the default (a2dissite default) but still the one was getting displayed was the subdomain1 not the subdomain2.
##FILENAME /etc/apache2/sites-available/subdomain2
 
<VirtualHost *>
        ServerName subdomain2.mydomain.com
 
        DocumentRoot /var/www/subdomain2/
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
 
        <Directory /var/www/subdomain2/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order deny,allow
                allow from all
        </Directory>
 
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
 
    ErrorLog  /var/log/apache2/subdomain2-error.log
    CustomLog /var/log/apache2/subdomain2-access.log combined
    TransferLog /var/log/apache2/subdomain2-transfer.log
 
</VirtualHost>

Open in new window

Raleigh GuevarraDevSecOpsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

osintsevCommented:
You do not forget to do `/ etc/init.d/apache2 restart`?
0
Raleigh GuevarraDevSecOpsAuthor Commented:
of course I already did that, actually it was /etc/init.d/apache2 reload but still pointing to subdomain1 not on subdomain2
0
osintsevCommented:
Please give output of this commands:
# ls -la /etc/apache2/sites-available/
# ls -la /etc/apache2/sites-enabled/

Open in new window

0
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

Raleigh GuevarraDevSecOpsAuthor Commented:
What I'm also expecting to get is I can access both domains even if I use the IP:

http://123.456.789.10/subdomain1  - Ok! accessible
http://123.456.789.10/subdomain2  - NOT OK! it goes to subdomain1 site
0
osintsevCommented:
And yet /etc/apache2/sites-available/subdomain1 file
0
Raleigh GuevarraDevSecOpsAuthor Commented:
I'm wondering that my phpmyadmin and pgpooladmin are both working fine

http://123.456.789.10/phpmyadmin
http://123.456.789.10/pgpooladmin

subdomain1 and subdomain2 almost identical except for their path
Webserver:/etc/apache2/sites-available# ls -la /etc/apache2/sites-available/
total 28
drwxr-xr-x 2 root root 4096 2009-05-29 02:02 .
drwxr-xr-x 7 root root 4096 2009-05-28 17:45 ..
-rw-r--r-- 1 root root  982 2009-05-28 14:43 default
-rw-r--r-- 1 root root 7366 2009-01-21 08:05 default-ssl
-rw-r--r-- 1 root root  600 2009-05-28 17:27 subdomain1
-rw-r--r-- 1 root root  646 2009-05-29 02:02 subdomain2
 
 
Webserver:/etc/apache2/sites-available# ls -la /etc/apache2/sites-enabled/
total 8
drwxr-xr-x 2 root root 4096 2009-05-28 17:28 .
drwxr-xr-x 7 root root 4096 2009-05-28 17:45 ..
lrwxrwxrwx 1 root root   25 2009-05-28 17:28 subdomain1 -> ../sites-available/subdomain1
lrwxrwxrwx 1 root root   23 2009-05-28 17:28 subdomain2 -> ../sites-available/subdomain2

Open in new window

0
Raleigh GuevarraDevSecOpsAuthor Commented:
I also noticed that when I access http://123.456.789.10/subdomain1 it will go to http://123.456.789.10/index.php
and again, for subdomain2 (http://123.456.789.10/subdomain2 it returned 404
0
osintsevCommented:
Check 'ServerName' directive in subdomain1 configuration file, pretty much what you missed it.
0
Raleigh GuevarraDevSecOpsAuthor Commented:
This is my subdomain1 host file
<VirtualHost *:80>
        
        ServerName subdomain1.mydomain.com
 
        DocumentRoot /var/www/subdomain1/
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
 
        <Directory /var/www/subdomain1/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order deny,allow
                allow from all
        </Directory>
 
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
 
        ErrorLog /var/log/apache2/subdomain1-error.log
        CustomLog /var/log/apache2/subdomain1-access.log combined
        TransferLog /var/log/apache2/subdomain1-transfer_log
 
</VirtualHost>

Open in new window

0
osintsevCommented:
Try change '<VirtualHost *>' in /etc/apache2/sites-available/subdomain2 to '<VirtualHost *:80>' and reload apache2.

Good idea now to see the error log in /var/log/apache2/subdomain1-error.log

 

0
Raleigh GuevarraDevSecOpsAuthor Commented:
Did that already and returned an error:

Webserver:/etc/apache2/sites-available# /etc/init.d/apache2 reload
Reloading web server config: apache2[Fri May 29 02:52:42 2009] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
0
Raleigh GuevarraDevSecOpsAuthor Commented:
#/var/log/apache2/subdomain1-error.log

[Fri May 29 10:24:15 2009] [error] [client 213.546.879.10] File does not exist: /var/www/subdomain1/subdomain2
0
Raleigh GuevarraDevSecOpsAuthor Commented:
When I access the subdomain2 using FQDN http://subdomain2.mydomain.com, it will display the contents of subdomain1. the address is subdomain2.mydomain.com but the contents it will display subdomain1
0
osintsevCommented:
Check the line 'NameVirtualHost *:80' in /etc/apache2/ports.conf (it should not be commented) - this is important. Also, set '<VirtualHost *:80>' in all virtual hosts definitions. Restart your apache, error '[warn] _default_ VirtualHost overlap on port 80, the first has precedence' should disappear.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Raleigh GuevarraDevSecOpsAuthor Commented:
thanks, that addressed the error as mentioned above and was displaying the contents of subdomain2 when used the fqdn http://subdomain2.mydomain.com but not displaying fully (missing images and dead links) and with http://123.456.789.10/subdomain2 it still returned 404. I checked again the subdomain1-error.log, it has this error:

#subdomain1-error.log
[Sat May 30 07:35:59 2009] [error] [client 213.546.879.10] File does not exist: /var/www/subdomain1/subdomain2, referer: http://subdomain2.mydomain.com/

it seems that it still going to open /var/www/subdomain1/subdomain2 instead of /var/www/subdomain2
0
osintsevCommented:
Turn back default virtual host (and reload apache2):
# a2ensite default

Open in new window

0
Xyptilon2Commented:
A few pointers:

- Configure the subdomains for a domain (virtualhost containers) before configuring the wildcard subdomain (if you have any), otherwise your subdomains will not work.

- If you want to support temporary URLs, like 1.2.3.4/~domain1.com then include a snippet in your configuration like:

# Add the following lines
<IfModule mod_userdir.c>
    UserDir /var/www/*
</IfModule>

Of course the module userdir needs to be enabled for this, it also assumes that your domains are in /var/www/* (where the * is domain1, domain2, domain3, etc).

0
koffuCommented:
try to
a2ensite subdomain1
a2ensite subdomain2

and be sure that your server's config have NameVirtualHost directive
http://httpd.apache.org/docs/1.3/mod/core.html#namevirtualhost

Syntax: NameVirtualHost addr[:port]
examples
NameVirtualHost 111.22.33.44
NameVirtualHost 111.22.33.44:8080
NameVirtualHost *
NameVirtualHost *:80

and dont forget to make apache reload at the end.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Distributions

From novice to tech pro — start learning today.