LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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
 
LinkBack Search this Thread
Old 12-11-2007, 08:04 AM   #1
intramaweb
LQ Newbie
 
Registered: May 2006
Location: Coventry, UK
Distribution: CentOS 5
Posts: 15

Rep: Reputation: 0
Thumbs up Apache2 NameVirtualHost not working


I'm trying to set up a virtual host on Apache2 (CentOS 5) but instead of the default site or the virtual site, all I am getting is the Apache test page.

/etc/sysconfig/network:
Code:
HOSTNAME=webserver
DNS entries on the local DNS server:
Code:
webserver    Host(A)    19.168.0.250
intranet    Host(A)    19.168.0.250
Relevant excerpts (hopefully) from httpd.conf:
Code:
Listen 192.168.0.250:80
ServerName webserver:80
UseCanonicalName Off
DocumentRoot "/var/www/html"

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    Allow Override None
    Order allow,deny
    Allow from all
</Directory>

<FilesMatch "^\.">
    Order allow,deny
    Deny from all
</FilesMatch>
<FilesMatch "~$">
    Order allow,deny
    Deny from all
</FilesMatch>

HostnameLookups Off

NameVirtualHost 192.168.0.250:80

<VirtualHost 192.168.0.250:80>
    DocumentRoot /var/www/vhost/intranet
    ServerName intranet
    ServerAlias intranet.domain.local
    AddType application/x-httpd-php .php
</VirtualHost>
<Directory /var/www/vhosts/intranet>
    AllowOverride AuthConfig
    Order allow,deny
    Allow from all
</Directory>
Permissions for the folders:
Code:
drwxr-xr-x 2 apache apache 4096 Dec  10 14:13 /var/www/html
drwxr-xr-x 11 apache apache 4096 Dec  7 14:41 /var/www/vhosts/intranet
Any ideas what I'm doing wrong? Cheers.

Last edited by intramaweb; 12-11-2007 at 08:16 AM. Reason: Added folder permissions
 
Old 12-11-2007, 10:12 AM   #2
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 194Reputation: 194
Change this:

Code:
NameVirtualHost 192.168.0.250:80

<VirtualHost 192.168.0.250:80>
    DocumentRoot /var/www/vhost/intranet
    ServerName intranet
    ServerAlias intranet.domain.local
    AddType application/x-httpd-php .php
</VirtualHost>
<Directory /var/www/vhosts/intranet>
    AllowOverride AuthConfig
    Order allow,deny
    Allow from all
</Directory>
To:

Code:
NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot /var/www/vhost/intranet
    ServerName intranet
    ServerAlias intranet.domain.local
    ServerPath /intranet
    AddType application/x-httpd-php .php
        <Directory /var/www/vhosts/intranet>
           AllowOverride AuthConfig
           Order allow,deny
           Allow from all
        </Directory>
</VirtualHost>
Basically for vhosts, always put any <Directory> tags within the VirtualHost it's intended for, just makes things easier to understand and read.
Secondly, if you only have one IP address, no reason to put it in the NameVirtualHost and VirtualHost, a simple *:80 will do just fine.
And In Apache2, I found with virtual hosts, it's best to use the ServerPath so it knows where to find the directory cause for some odd reason it reverts back to the main configurations document root.

ServerPath = Legacy URL pathname for a name-based virtual host that is accessed by an incompatible browser
 
Old 12-11-2007, 10:35 AM   #3
intramaweb
LQ Newbie
 
Registered: May 2006
Location: Coventry, UK
Distribution: CentOS 5
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks for the tips. I've made all these changes but unfortunately, I still have the same problem.

I'm thinking that the problem must not be with the vhosts, as browsing to http://webserver/ aught to show me what's in the DocumentRoot but this is also just showing me the test page.

My understanding of the test page is that it redirects a 403 error to the the test page location so I thought there might be a permissions problem but I've tried both the commands below on the DocumentRoot path and on the vhost path to no avail
Code:
chown apache:apache -R
chmod 777 -R
 
Old 12-11-2007, 10:40 AM   #4
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 194Reputation: 194
Whenever I have virtual hosts, I always make a virtual host for the main configuration as well. Try that. If you don't need the test page though, just make your main configuration and document root the one you intend to use as well.
 
Old 12-11-2007, 11:46 AM   #5
complich8
Member
 
Registered: Oct 2007
Distribution: rhel, fedora, gentoo, ubuntu, freebsd
Posts: 104

Rep: Reputation: 15
that's just typo-tastic...

local dns: 19.168 -> 192.168

apache config DocumentRoot: /var/www/vhost/intranet -> /var/www/vhosts/intranet
or, if that's right,
apache config Directory: /var/www/vhosts/intranet -> /var/www/vhost/internet
(take your pick)

Don't 777 your stuff unless you know what you're doing. 755 is absolutely sufficient. Also, documentroot doesn't need to be owned by apache.

If all else fails, you should check your apache error_log, which is usually pretty enlightening.

Also, do you know if you're running an SELinux config?

Last edited by complich8; 12-11-2007 at 11:47 AM.
 
Old 12-12-2007, 04:05 AM   #6
intramaweb
LQ Newbie
 
Registered: May 2006
Location: Coventry, UK
Distribution: CentOS 5
Posts: 15

Original Poster
Rep: Reputation: 0
Sorry - the typos were just in my hurriedly typed post. The actual settings are OK.

Yes - SELinux config. Here's the tail end of the error log:
Code:
[Wed Dec 12 09:09:30 2007] [notice] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[Wed Dec 12 09:09:30 2007] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Dec 12 09:09:30 2007] [notice] Digest: generating secret for digest authentication ...
[Wed Dec 12 09:09:30 2007] [notice] Digest: done
[Wed Dec 12 09:09:32 2007] [notice] mod_python: Creating 4 session mutexes based on 256 max processes and 0 max threads.
[Wed Dec 12 09:09:33 2007] [notice] Apache/2.2.3 (CentOS) configured -- resuming normal operations
[Wed Dec 12 09:51:20 2007] [error] [client 192.168.0.251] (13)Permission denied: access to /index.php denied
[Wed Dec 12 09:51:23 2007] [error] [client 192.168.0.251] (13)Permission denied: access to /index.php denied
It's saying permission denied, but I don't know what the cause is in this instance. Is it something obvious? Thanks.
 
Old 12-12-2007, 05:54 AM   #7
Flyte
LQ Newbie
 
Registered: Dec 2007
Distribution: Fedora, CentOS, Debian
Posts: 23

Rep: Reputation: 2
Try typing 'setenforce 0' at the command prompt as root on the webserver.

This will temporarily turn off SELinux's enforcing. If it works after doing this, then you need to look at your SELinux policies on the files you're trying to serve.

Unfortunately I can't help you any further with that!

PS. to turn enforcing back on, type 'setenforce 1'.
 
Old 12-12-2007, 07:59 AM   #8
intramaweb
LQ Newbie
 
Registered: May 2006
Location: Coventry, UK
Distribution: CentOS 5
Posts: 15

Original Poster
Rep: Reputation: 0
Fantastic! Turning off SELinux sorted the problem... Another thing to add to me list of things I need to read up on...

Cheers!
 
  


Reply

Tags
apache, apache2, centos, centos5, selinux, virtual host


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
apache2 error - namevirtualhost *:0 has no virtualhosts? tiger.woods Ubuntu 2 04-09-2007 10:26 AM
NameVirtualHost not working: Akways default to /var/www/html Swakoo Linux - Server 6 04-09-2007 04:09 AM
apache2 NameVirtualHost gabsik Linux - Networking 3 01-18-2007 02:26 PM
NameVirtualHost IP# has no VirtualHosts? DigiCrime Linux - Networking 2 10-11-2004 12:24 AM
Another NameVirtualHost problem somroj Linux - Software 1 09-29-2003 04:20 AM


All times are GMT -5. The time now is 11:31 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration