我的网络服务器使用Apache2托管一个主域和一个子域,其中的主域只是一个占位符HTML页面,而子域是python / django应用程序。
在A记录添加到我的DNS设置(在GoDaddy中)以启用子域和关联的Apache VirtualHost之后,我遇到了一个有趣的问题。
问题是导航到我的子域www.testing.mysite.com
可以正常工作,但是主域www.mysite.com
却导致400错误请求错误。主域和子域最初都起作用。
已通过“使用http到https重定向的“我们加密”功能在主域和子域VirtualHosts上启用了SSL,并且在这两种情况下都正常工作,直到问题突然出现。
GoDaddy记录如下所示
Type Name Value TTL
a @ xx.xx.xxx.xxx 600 seconds
a admin xx.xx.xxx.xxx 1 Hour
a staging xx.xx.xxx.xxx 1 Hour
a testing xx.xx.xxx.xxx 1 Hour
cname www @ 1 Hour
主域的Apache配置如下:
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com
ServerAdmin admin@mysite.com
DocumentRoot /var/www/mysite/public_html
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
#Include conf-available/serve-cgi-bin.conf
RewriteEngine on
RewriteCond %{SERVER_NAME} =mysite.com [OR]
RewriteCond %{SERVER_NAME} =www.mysite.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerName mysite.com
ServerAlias www.mysite.com
ServerAdmin admin@mysite.com
DocumentRoot /var/www/mysite/public_html
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
#Include conf-available/serve-cgi-bin.conf
SSLCertificateFile /etc/letsencrypt/live/mysite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mysite.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
子域的Apache配置如下:
WSGIDaemonProcess mysite_demo python-path=/var/www/mysite-testing
WSGIProcessGroup mysite_demo
WSGIScriptAlias / /var/www/mysite-testing/mysite_demo/wsgi.py
<VirtualHost *:80>
ServerAdmin admin@mysite.com
DocumentRoot /var/www/mysite-testing
ServerAlias www.testing.mysite.com
ServerName testing.mysite.com
Alias /static /var/www/mysite-testing/static
<Directory /var/www/mysite-testing/static>
Require all granted
</Directory>
<Directory /var/www/mysite-testing/mysite_demo>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =testing.mysite.com [OR]
RewriteCond %{SERVER_NAME} =www.testing.mysite.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin admin@mysite.com
DocumentRoot /var/www/mysite-testing
ServerAlias www.testing.mysite.com
ServerName testing.mysite.com
Alias /static /var/www/mysite-testing/static
<Directory /var/www/mysite-testing/static>
Require all granted
</Directory>
<Directory /var/www/mysite-testing/mysite_demo>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/testing.mysite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/testing.mysite.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
在解决此问题方面将提供帮助。谢谢。