很长时间的听众第一次打电话..。
我已经运行Apache多年了,并且设置了多个服务器。这一次让我很难过,我只是找不到这个问题。我在这里和其他地方见过许多线程,它们都有VirtualHost问题和错误的DocumentRoot,但是这些线程都没有帮助我。
服务器运行CentOS7.5,启用SELinux,Apache2.4.33。
我想运行两个VirtualHosts。由于某种原因,辅助VH没有提供正确的文件。改变VH的顺序并不重要。最后一件事是硬编码一个默认的DocumentRoot (/var/www/html),然后将每个VH放在它自己的单独目录(/var/www/VirtualHost)中。
下面是我当前的virtualhost.conf文件:
#Set a default DocumentRoot
DocumentRoot /var/www/html
ServerAdmin webmaster@example1.com
DocumentRoot /var/www/example2.com
ServerName example2.com
ServerAlias www.example2.com
Options -Indexes +FollowSymLinks +MultiViews
Order allow,deny
Allow from all
ServerAdmin webmaster@example1.com
DocumentRoot /var/www/example1.com
ServerName example1.com
ServerAlias www.example1.com
Options -Indexes +FollowSymLinks +MultiViews
Order allow,deny
Allow from all我在日志中看到的是,所有请求都试图从默认的/var/www/html中得到服务。
我临时更改了所使用的日志格式,以便能够看到所使用的ServerName,以及用于验证路径的确切文件名。
LogFormat "%v %f %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined在本地服务器上,我发出以下两个命令来测试:
wget http://example1.com/index.html
wget http://example2.com/images/logo.jpg我的访问日志显示如下:
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)"从日志中,我可以看到正确的域正在显示,但文件路径显然是错误的,Apache试图从默认的DocumentRoot中提取请求的文件,而不是为VirtualHosts定义的DocumentRoot,后者应该是/var/www/VirtualHosts(X).com。
httpd -S命令的输出如下:
[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]$任何帮助都是非常感谢的!
发布于 2018-07-19 21:55:43
我已经解决了我的问题,这与我在上面发布的任何东西都没有任何关系。希望这能帮到其他人。
我问题的根本原因是我安装了PHP 7,特别是php的安装。我遵循的指南建议创建一个具有以下内容的fpm.conf文件:
# PHP scripts setup
ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/var/www/html
Alias / /var/www/html/多亏了这个配置,我的DocumentRoot被重写为我所有的VirtualHosts到上面的路径。直到我抛出所有搜索'/var/www‘的配置文件时,我才看到这个文件。
进一步谷歌如何将PHP与VirtualHosts结合起来,我找到了一个在每个VirtualHost块中包含这个代码块的页面:
# 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"将这个块添加到我的两个VirtualHosts中,删除旧的fpm.conf文件并重新启动Apache解决了我的问题,现在每个VHost都使用了正确的DocumentRoot。我的PHP文件是否会被正确地服务还有待确定,但至少现在我走上了正确的道路。
https://serverfault.com/questions/922527
复制相似问题