我正在尝试排除一个 Apache 实例的故障,该实例在上周重新启动之前一直运行良好。现在似乎没有加载 vhost,我不知道原因。
任何访问 app.domain.com 的尝试都应该转发到虚拟主机的文档根目录,实际上指向主服务器的文档根目录。
httpd.conf 如下(有一些小混淆)
ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User web-user
Group web-group
ServerAdmin [email protected]
DocumentRoot "/var/www/html"
<Directory />
AllowOverride all
Require all denied
</Directory>
<Directory "/var/www">
#Previous value none
AllowOverride none
# Allow open access:
Require all granted
</Directory>
# Further relax access to the default document root:
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
################### VHOST Directory #######################
<Directory "/apps/app/public_html">
Order allow,deny
Allow from all
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf
IncludeOptional sites-enabled/*.conf
位于 sites-enabled 中的 vhost.conf 文件
<VirtualHost *:443>
ServerName app.domain.com
ServerAlias app.domain.com
DocumentRoot /apps/app/public_html
ErrorLog /var/www/app/error_log
CustomLog /var/www/app/access_log combined
</VirtualHost>
我在主文档根目录(/var/www/html)中还有一个 .htaccess 文件,它将任何纯文本流量重定向到 SSL 网站。
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://app.domain.com/$1 [R,L]
有人能找出我的配置中的错误吗?
编辑:httpd -S 的结果
[root@server]# httpd -S
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using app.domain.com. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:443 is a NameVirtualHost
default server app.domain.com (/etc/httpd/conf.d/ssl.conf:56)
port 443 namevhost app.domain.com (/etc/httpd/conf.d/ssl.conf:56)
port 443 namevhost app.domain.com (/etc/httpd/sites-enabled/app.conf:1)
alias app.domain.com
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex authdigest-opaque: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: 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
PidFile: "/run/httpd/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="web-user" id=1001
Group: name="web-group" id=1001
答案1
您的问题是现在您在两个不同的文件中定义了相同的虚拟主机,因此第一个文件是正在使用的:
port 443 namevhost app.domain.com (/etc/httpd/conf.d/ssl.conf:56)
尽管另一个被忽略了:
port 443 namevhost app.domain.com (/etc/httpd/sites-enabled/app.conf:1)
永远不要使用 ServerName 定义两个虚拟主机,因为如果这样做,第一个匹配将获得所有请求,而第二个虚拟主机将被忽略。