![Apache 会在一段时间后返回默认虚拟主机,并且仅适用于某些虚拟主机](https://linux22.com/image/759591/Apache%20%E4%BC%9A%E5%9C%A8%E4%B8%80%E6%AE%B5%E6%97%B6%E9%97%B4%E5%90%8E%E8%BF%94%E5%9B%9E%E9%BB%98%E8%AE%A4%E8%99%9A%E6%8B%9F%E4%B8%BB%E6%9C%BA%EF%BC%8C%E5%B9%B6%E4%B8%94%E4%BB%85%E9%80%82%E7%94%A8%E4%BA%8E%E6%9F%90%E4%BA%9B%E8%99%9A%E6%8B%9F%E4%B8%BB%E6%9C%BA.png)
开始:我在 CentOS6 上安装了 httpd,多年来运行良好,配置了许多虚拟主机(它被配置为许多网站的反向代理)。最近我将我的机器升级到 CentOS8,并将 httpd 安装升级到 2.4.37
我使用了旧的配置文件,只更改了一些过时的指令。服务启动正常,所有虚拟主机均按预期运行。
问题:有时(通常一周两次)我的一个虚拟主机会随机停止工作,httpd 只是停止识别它并返回默认虚拟主机。其他虚拟主机继续正常工作。
重新启动服务(编辑:但没有通过服务重新加载)使失败的虚拟主机恢复正常。
感谢您的帮助
编辑: 我添加了上周出现问题的虚拟主机的配置:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName mydomain.dm
ServerAlias www.mydomain.dm
ServerAlias mydomain.com
ServerAlias www.mydomain.com
ErrorLog "logs/mydomain.dm_error_log"
CustomLog "logs/mydomain.dm_access_log" combined
SetEnvIf User-Agent ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^ http://www.mydomain.dm%{REQUEST_URI} [R,L,NE]
<IfModule mod_proxy.c>
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
#################
# ERRORS
#################
ProxyPass /errorpages/ !
ProxyPass / http://192.168.50.181:8080/
ProxyPassReverse / http://192.168.50.181:8080/
</IfModule>
</VirtualHost>
我有一些通用指令:
AcceptFilter http none
AcceptFilter https none
ServerTokens Prod
KeepAlive On
太感谢了
答案1
经过两年的故障排除,我找到了答案,我将其发布出来以作记录,因为世界上没有人会在未来遭受这种痛苦。
Apache 有一个每日 cron 运行 logrotate (/etc/cron.daily/httpd) 并进行日志打包,然后重新启动/重新加载服务。在重新启动/重新加载期间,Apache 服务将对其 IP 进行反向查找。公司的 MS DNS 服务器有一个反向查找区域,其中 IP 可以与名称进行转换。如果为一个 IP 记录了多个名称,则循环仅提供其中一个。
# nslookup 192.168.50.5 192.168.50.1
;; Truncated, retrying in TCP mode.
5.50.168.192.in-addr.arpa name = www.mydomain.dm
5.50.168.192.in-addr.arpa name = www.mydomain.com
5.50.168.192.in-addr.arpa name = mydomain.com
5.50.168.192.in-addr.arpa name = service1.com
5.50.168.192.in-addr.arpa name = service2.com
5.50.168.192.in-addr.arpa name = service3.com
我忘记了 /etc/httpd/conf.d/00-default 中的默认配置:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
如果 VirtualHost 没有 ServerName 选项,那么 apache 会尝试反向查找以了解机器名称,在我的例子中,它会四舍五入反向查找区域并随机选择一个服务名称。因此默认配置与好的配置重叠。
这种行为如下所述: https://httpd.apache.org/docs/trunk/dns-caveats.html
结论:如果您遇到此问题,只需检查您的 VirtualHosts 配置和 DNS 反向查找区域。