Long time listener, first time
caller...
I've been running Apache for years,
and have set up multiple servers. This one is giving me a hard time and I just can't
spot the issue. I've seen a number of threads here and elsewhere with VirtualHost
problems and the wrong DocumentRoot being served, but none of those threads have helped
me out.
Server is running Centos 7.5, SELinux
enabled, Apache 2.4.33.
I'm wanting
to run two VirtualHosts. For some reason, the secondary VH isn't serving the right
files. Changing the order of the VH didn't matter. Last thing I tried was hard coding a
default DocumentRoot (/var/www/html) and then putting each VH in its own separate
directory (/var/www/VirtualHost).
Here is my
current virtualhost.conf
file:
#Set a default
DocumentRoot
DocumentRoot /var/www/html
*:80>
ServerAdmin webmaster@example1.com
DocumentRoot /var/www/example2.com
ServerName example2.com
ServerAlias
www.example2.com
/var/www/example2.com>
Options -Indexes +FollowSymLinks
+MultiViews
Order allow,deny
Allow from
all
*:80>
ServerAdmin webmaster@example1.com
DocumentRoot
/var/www/example1.com
ServerName example1.com
ServerAlias
www.example1.com
/var/www/example1.com>
Options -Indexes +FollowSymLinks
+MultiViews
Order allow,deny
Allow from
all
What
I'm seeing in my logs is that all requests are trying to be served from /var/www/html,
the default.
I have temporarily changed the log
format used so that I can see the ServerName used, and the exact filename being
referenced to verify the
path.
LogFormat "%v %f %h %l %u %t
\"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
combined
On
the local server, I issue the following two commands to
test:
wget
http://example1.com/index.html
wget
http://example2.com/images/logo.jpg
My
access log shows
this:
example1.com
/var/www/html/index.html 192.168.1.2 - - [18/Jul/2018:11:48:08 -0500] "GET /index.html
HTTP/1.1" 404 208 "-" "Wget/1.14 (linux-gnu)"
example2.com
/var/www/html/images 192.168.1.2 - - [18/Jul/2018:11:48:12 -0500] "GET /images/logo.jpg
HTTP/1.1" 404 213 "-" "Wget/1.14
(linux-gnu)"
From the
log, I can see that the correct domain is showing, but the file path is clearly wrong,
Apache is trying to pull the requested files from the default DocumentRoot, and not the
DocumentRoot defined for the VirtualHosts, which would have been
/var/www/example(x).com.
Output of the httpd -S
command as follows:
[wright@web2
conf.d]$ httpd -S
AH00558: httpd: Could not reliably determine the server's
fully qualified domain name, using web2.local. Set the 'ServerName' directive globally
to suppress this message
VirtualHost configuration:
*:80
is a NameVirtualHost
default server example2.com
(/etc/httpd/conf.d/vhosts.conf:4)
port 80 namevhost example2.com
(/etc/httpd/conf.d/vhosts.conf:4)
alias www.example2.com
port 80
namevhost example1.com (/etc/httpd/conf.d/vhosts.conf:17)
alias
www.example1.com
ServerRoot: "/etc/httpd"
Main DocumentRoot:
"/var/www/html"
Main ErrorLog:
"/etc/httpd/logs/error_log"
Mutex authdigest-opaque:
using_defaults
Mutex watchdog-callback: using_defaults
Mutex
proxy-balancer-shm: using_defaults
Mutex rewrite-map:
using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex
authdigest-client: using_defaults
Mutex lua-ivm-shm:
using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy:
using_defaults
Mutex authn-socache: using_defaults
Mutex
ssl-cache: using_defaults
Mutex default: dir="/run/httpd/"
mechanism=default
Mutex mpm-accept: using_defaults
Mutex
cache-socache: using_defaults
PidFile:
"/run/httpd/httpd.pid"
Define: DUMP_VHOSTS
Define:
DUMP_RUN_CFG
User: name="apache" id=48 not_used
Group: name="apache"
id=48 not_used
[wright@web2
conf.d]$
Any
help is appreciated!
I've
managed to resolve my issue, and naturally it had nothing to do with anything I posted
above. Hopefully this will help someone else down the
road.
The root cause of my issue turned out to
be my installation of PHP 7, specifically with the setup of php-fpm. The guide I
followed suggested creating an fpm.conf file with the
following:
# PHP scripts setup
ProxyPassMatch ^/(.*.php)$
fcgi://127.0.0.1:9000/var/www/html
Alias /
/var/www/html/
Thanks
to this config, my DocumentRoot was getting rewritten for all of my VirtualHosts to the
above path. It wasn't until I dumped all of my config files searching for '/var/www'
that I came across this file.
Further googling
on how to incorporate PHP-FPM with VirtualHosts led me to a page that had this code
block within each VirtualHost
block:
\.php$>
# 2.4.10+ can proxy to unix socket
#
SetHandler "proxy:unix:/var/run/php5-fpm.sock|fcgi://localhost/"
#
Else we can just use a tcp socket:
SetHandler
"proxy:fcgi://127.0.0.1:9000"
Adding
this block to both of my VirtualHosts, and removing the old fpm.conf file and restarting
Apache resolved my issue, the correct DocumentRoot was now being used for each VHost. It
still remains to be determined if my PHP files are going to be served up correctly, but
at least now I'm on the right path.
Comments
Post a Comment