我试图解决一个工作正常的Apache实例,直到上周重新启动。 它现在看起来好像虚拟主机没有被加载,我不明白为什么。
任何尝试访问应该转发到虚拟主机的文档根目录的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
位于已启用站点的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文件,用于将任何纯文本stream量redirect到SSL网站。
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://app.domain.com/$1 [R,L]
任何人都可以识别我的configuration中的错误?
编辑: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
你的问题是现在你有两个不同的文件定义相同的虚拟主机,所以第一个是正在使用的:
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定义两个虚拟主机,因为如果这样做,首先匹配将获得所有请求,第二个虚拟主机将被忽略。