LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-19-2010, 02:55 AM   #1
dstu
Member
 
Registered: Dec 2006
Posts: 37

Rep: Reputation: 0
Apache Virtual Servers (CentOS 5.5)


Hello,

I activated several virtual servers on my Apache, and since then, all the domains I use are directed to the directory of a single one of them (in this case, /var/www/mydomain.com).

This is the config section:

Code:
<VirtualHost *>
DocumentRoot "/var/www/mydomain.com"
ServerName mydomain.com
<Directory "/var/www/mydomain.com">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
<VirtualHost *>
DocumentRoot "/var/www/mydomain2.com"
ServerName mydomain2.com
<Directory "/var/www/mydomain2.com">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
<VirtualHost *>
DocumentRoot "/var/www/mydomain.com"
ServerName www.mydomain.com
<Directory "/var/www/mydomain.com">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/mydomain2.com
ServerName www.mydomain2.com
<Directory "/var/www/mydomain2.com">
allow from all
Options +Indexes
</Directory>
LogLevel debug
</VirtualHost>
Can anyone help identify why this happens?

Thanks.
 
Old 09-19-2010, 03:42 AM   #2
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 101Reputation: 101
It's Name-based Virtual Host. Do you have a NameVirtualHost directive? What happen when you restart Apache? Did you take a look at log file?
 
Old 09-19-2010, 03:44 AM   #3
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
The first virtual host is used for requests without a known domain name, so perhaps your config is suspect.
Personally I would use the following :

Code:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot "/var/www/mydomain.com"
<Directory "/var/www/mydomain.com">
     Allow from all
     Options +Indexes
</Directory>
SetEnv SITE_ROOT /var/www/mydomain.com
SetEnv SITE_HTMLROOT /var/www/mydomain.com
</VirtualHost>

<VirtualHost *:80>
ServerName mydomain2.com
ServerAlias www.mydomain2.com
DocumentRoot "/var/www/mydomain2.com"
<Directory "/var/www/mydomain2.com">
     Allow from all
     Options +Indexes
</Directory>
SetEnv SITE_ROOT /var/www/mydomain2.com
SetEnv SITE_HTMLROOT /var/www/mydomain2.com
LogLevel debug
</VirtualHost>
But on my sites, I have the document root, separate from the site root:
DocumentRoot "/var/www/mydomain2.com/html"
SetEnv SITE_ROOT /var/www/mydomain2.com
SetEnv SITE_HTMLROOT /var/www/mydomain2.com/html


Have you verified the config ?

Code:
httpd -S

Last edited by smoker; 09-19-2010 at 03:52 AM.
 
Old 09-19-2010, 11:23 AM   #4
dstu
Member
 
Registered: Dec 2006
Posts: 37

Original Poster
Rep: Reputation: 0
Quote:
Have you verified the config ?
Code:
httpd -S

That's the result I get:
Code:
[root@servername ~]# httpd -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
_default_:443          servername.mydomain.com (/etc/httpd/conf.d/ssl.conf:81)
*:*                    mydomain.com (/etc/httpd/conf/httpd.conf:992)
*:*                    mydomain2.com (/etc/httpd/conf/httpd.conf:1000)
*:*                    www.mydomain.com (/etc/httpd/conf/httpd.conf:1008)
*:80                   www.mydomain2.com (/etc/httpd/conf/httpd.conf:1016)
Syntax OK
I think that there's something missing and that it simply takes the first virtual server for all names and ignores the "ServerName" entry.
 
Old 09-19-2010, 03:42 PM   #5
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
Did you check the NameVirtualHost directive as quanta suggested ? If that's not enabled then only the main server site will be serviced.
 
Old 09-20-2010, 02:25 AM   #6
dstu
Member
 
Registered: Dec 2006
Posts: 37

Original Poster
Rep: Reputation: 0
Thumbs up It works!!

Thanks guys. I missed it at first, because in my config file, that directive was followed by *:80, so I didn't think it was related.

One thing left now. If I go to the server by its IP address (no domain name), it goes to the mydomain.com directory (the first virtual server), but I would like it to go to the /var/www/html directory, just like the https does. Where should I define that? Should I create another virtual server with any/any settings?

Thanks.
 
Old 09-20-2010, 04:54 PM   #7
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
Define the site correctly. The first virtual site should have DocumentRoot defined the way you want it. Personally I wouldn't have all the sites under /var/www , I would put them in separate directories :

/home/site1/www/html/
/home/site2/www/html/

etc, etc.

Sites can be anywhere, you just specify the directory in the httpd.conf
 
Old 09-21-2010, 05:43 AM   #8
dstu
Member
 
Registered: Dec 2006
Posts: 37

Original Poster
Rep: Reputation: 0
Smile

Hi,

I just placed the default virtual server first int he list and all the named ones below, and now everything works, just as I want it.

Thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Apache + virtual servers yussef Debian 1 01-31-2005 09:48 PM
Apache + virtual servers yussef Linux - Software 0 01-08-2005 01:05 PM
apache virtual servers granny Linux - Networking 3 09-10-2003 11:42 PM
apache virtual servers knueven7 Linux - Software 2 03-31-2003 12:14 PM
Apache and Virtual Servers... BaerRS Linux - General 2 03-08-2002 09:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:24 PM.

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