Skip to main content

Apache 2.4 using default DocumentRoot instead of VirtualHost DocumentRoot

itemprop="text">

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!


itemprop="text">
class="normal">Answer



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

Popular posts from this blog

linux - iDRAC6 Virtual Media native library cannot be loaded

When attempting to mount Virtual Media on a iDRAC6 IP KVM session I get the following error: I'm using Ubuntu 9.04 and: $ javaws -version Java(TM) Web Start 1.6.0_16 $ uname -a Linux aud22419-linux 2.6.28-15-generic #51-Ubuntu SMP Mon Aug 31 13:39:06 UTC 2009 x86_64 GNU/Linux $ firefox -version Mozilla Firefox 3.0.14, Copyright (c) 1998 - 2009 mozilla.org On Windows + IE it (unsurprisingly) works. I've just gotten off the phone with the Dell tech support and I was told it is known to work on Linux + Firefox, albeit Ubuntu is not supported (by Dell, that is). Has anyone out there managed to mount virtual media in the same scenario?

hp proliant - Smart Array P822 with HBA Mode?

We get an HP DL360 G8 with an Smart Array P822 controller. On that controller will come a HP StorageWorks D2700 . Does anybody know, that it is possible to run the Smart Array P822 in HBA mode? I found only information about the P410i, who can run HBA. If this is not supported, what you think about the LSI 9207-8e controller? Will this fit good in that setup? The Hardware we get is used but all original from HP. The StorageWorks has 25 x 900 GB SAS 10K disks. Because the disks are not new I would like to use only 22 for raid6, and the rest for spare (I need to see if the disk count is optimal or not for zfs). It would be nice if I'm not stick to SAS in future. As OS I would like to install debian stretch with zfs 0.71 as file system and software raid. I have see that hp has an page for debian to. I would like to use hba mode because it is recommend, that zfs know at most as possible about the disk, and I'm independent from the raid controller. For us zfs have many benefits,

apache 2.2 - Server Potentially Compromised -- c99madshell

So, low and behold, a legacy site we've been hosting for a client had a version of FCKEditor that allowed someone to upload the dreaded c99madshell exploit onto our web host. I'm not a big security buff -- frankly I'm just a dev currently responsible for S/A duties due to a loss of personnel. Accordingly, I'd love any help you server-faulters could provide in assessing the damage from the exploit. To give you a bit of information: The file was uploaded into a directory within the webroot, "/_img/fck_uploads/File/". The Apache user and group are restricted such that they can't log in and don't have permissions outside of the directory from which we serve sites. All the files had 770 permissions (user rwx, group rwx, other none) -- something I wanted to fix but was told to hold off on as it wasn't "high priority" (hopefully this changes that). So it seems the hackers could've easily executed the script. Now I wasn't able