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
<VirtualHost *:80>
ServerAdmin webmaster@example1.com
DocumentRoot /var/www/example2.com
ServerName example2.com
ServerAlias www.example2.com
</VirtualHost>
<Directory /var/www/example2.com>
Options -Indexes +FollowSymLinks +MultiViews
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerAdmin webmaster@example1.com
DocumentRoot /var/www/example1.com
ServerName example1.com
ServerAlias www.example1.com
</VirtualHost>
<Directory /var/www/example1.com>
Options -Indexes +FollowSymLinks +MultiViews
Order allow,deny
Allow from all
</Directory>
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!