问题
访问studentmossa.domain.com
结果重定向至server.domain.com
。
简短有价值的信息
我正在运行 Fedora 31(内核 5.5.15-200.fc31.x86_64)Apache/2.4.43 (Fedora)
。
我有四个网站(1 个域)由 Apache 的虚拟主机管理。
domain.com
nextcloud.domain.com
server.domain.com
studentmossa.domain.com
apachectl configtest
给出:
语法正确
httpd -S
给出:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server domain.com (/etc/httpd/conf.d/domain.com.conf:2)
port 80 namevhost domain.com (/etc/httpd/conf.d/domain.com.conf:2)
alias domain.com
port 80 namevhost nextcloud.domain.com (/etc/httpd/conf.d/nextcloud.domain.com.conf:2)
alias nextcloud.domain.com
port 80 namevhost studentmossa.domain.com (/etc/httpd/conf.d/server.domain.com.conf:2)
alias server.domain.com
port 80 namevhost studentmossa.domain.com (/etc/httpd/conf.d/studentmossa.domain.com.conf:2)
alias studentmossa.domain.com
*:443 is a NameVirtualHost
default server domain.com (/etc/httpd/conf.d/domain.com.conf:13)
port 443 namevhost domain.com (/etc/httpd/conf.d/domain.com.conf:13)
alias domain.com
port 443 namevhost nextcloud.domain.com (/etc/httpd/conf.d/nextcloud.domain.com.conf:15)
alias nextcloud.domain.com
port 443 namevhost studentmossa.domain.com (/etc/httpd/conf.d/server.domain.com.conf:11)
alias server.domain.com
port 443 namevhost studentmossa.domain.com (/etc/httpd/conf.d/ssl.conf:56)
port 443 namevhost studentmossa.domain.com (/etc/httpd/conf.d/studentmossa.domain.com.conf:16)
alias studentmossa.domain.com
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/"
Main ErrorLog: "/etc/httpd/logs/error_log"
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="/etc/httpd/run/" mechanism=default
Mutex cache-socache: using_defaults
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
PidFile: "/etc/httpd/run/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48
Group: name="apache" id=48
server.domain.com
是来自的代理http://本地主机/:19999(这是一个 netdata 设置)
以下是的配置文件server.domain.com
:
ServerName server.domain.com
<VirtualHost *:80>
ServerAlias server.domain.com
ErrorLog /var/log/httpd/server.domain.com/non_https_error.log
CustomLog /var/log/httpd/server.domain.com/non_https_access.log combined
Redirect / https://server.domain.com
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAlias server.domain.com
ErrorLog /var/log/httpd/server.domain.com/non_https_error.log
CustomLog /var/log/httpd/server.domain.com/non_https_access.log combined
RewriteEngine on
ProxyRequests off
ProxyPreserveHost On
<Proxy *>
Require all granted
</Proxy>
ProxyPass "/" "http://localhost:19999/" connectiontimeout=5 timeout=30 keepalive=on
ProxyPassReverse "/" "http://localhost:19999/"
SSLEngine on
SSLProtocol all -TLSv1 -TLSv1.1
SSLCipherSuite HIGH:!aNULL:!MD5:!3DES
SSLHonorCipherOrder on
SSLCertificateFile /etc/letsencrypt/live/server.domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/server.domain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
以下是的配置文件studentmossa.domain.com
:
ServerName studentmossa.domain.com
<VirtualHost *:80>
ServerAlias studentmossa.domain.com
ServerName studentmossa.domain.com
ErrorLog /var/log/httpd/studentmossa.domain.com/non_https_error.log
CustomLog /var/log/httpd/studentmossa.domain.com/non_https_access.log combined
Redirect / https://studentmossa.domain.com
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAlias studentmossa.domain.com
DocumentRoot /var/www/domain/studentmossa.domain.com/
ErrorLog /var/log/httpd/studentmossa.domain.com/non_https_error.log
CustomLog /var/log/httpd/studentmossa.domain.com/non_https_access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/studentmossa.domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/studentmossa.domain.com/privkey.pem
</VirtualHost>
</IfModule>
我尝试过
我尝试过更改重定向规则,而不是Redirect / https://studentmossa.domain.com
尝试过:
#RewriteEngine on
#RewriteCond %{SERVER_NAME} =studentmossa.domain.com
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
在所有虚拟主机上。它给出了相同的结果,当然,改变SERVER_NAME
任何帮助表示感谢
答案1
通过将其放入块ServerName
内<VirtualHost>
,有效地解决了问题。