我在服务器上配置了两个子域(主域和暂存域),对于暂存域,它返回两个不同的路径。有时它返回正确的路径(/var/www/html_staging
),但有时(当您刷新 Web 浏览器几次或当您转到子页面时)它返回主网站(/var/www/html
)
Ubuntu 16.04 上的 Apache 2.4
有 3 个 vhost 配置,两个用于主网站,一个用于暂存。vhost 配置中端口 80 有一个从 http 到 https 的重定向。
000-默认.conf:
<VirtualHost *:80>
ServerName website.example.com
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
ServerAdmin [email protected]
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
默认-ssl.conf:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin [email protected]
DocumentRoot /var/www/html
ServerName website.example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCipherSuite ALL:!EXP:!NULL:!ADH:!LOW
SSLCertificateFile /etc/apache2/ssl/*.example.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/*.example.com.key
SSLCACertificateFile /etc/apache2/ssl/bundle.crt
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
</IfModule>
staging.conf:
<VirtualHost *:80>
ServerName websitestaging.example.com
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
ServerAdmin [email protected]
DocumentRoot /var/www/html_staging
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName websitestaging.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/html_staging
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCipherSuite ALL:!EXP:!NULL:!ADH:!LOW
SSLCertificateFile /etc/apache2/ssl/*.example.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/*.example.com.key
SSLCACertificateFile /etc/apache2/ssl/bundle.crt
</VirtualHost>
</IfModule>
输出apache2ctl -S
VirtualHost configuration:
*:80 is a NameVirtualHost
default server website.example.com (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost website.example.com (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost websitestaging.example.com (/etc/apache2/sites-enabled/staging.conf:1)
*:443 is a NameVirtualHost
default server website.example.com (/etc/apache2/sites-enabled/default-ssl.conf:2)
port 443 namevhost website.example.com (/etc/apache2/sites-enabled/default-ssl.conf:2)
port 443 namevhost websitestaging.example.com (/etc/apache2/sites-enabled/staging.conf:15)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
这种行为的原因是什么?为什么只有有时暂存区会从正确路径加载网站,而有时却从主路径加载?主网站加载正确,这仅影响暂存区。
答案1
万一您遇到与上述相同的问题。只需重新启动整个服务器,而不仅仅是 Apache。服务器重新启动后,一切都会正常工作。可能是某种缓存或配置尚未正确删除,并且影响了整个服务器。