我正在尝试按照此答案https://webmasters.stackexchange.com/a/42248中的第一种方法将我的网站 mysite.com 重定向到 www.mysite.com 。该网站使用Flask with Python 2.7.6,在Ubuntu 14.04上运行。
下面是它的配置(文件名:www.mysite.co.conf):
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.mysite.co
DocumentRoot "/var/www/jcapp"
WSGIDaemonProcess jcapp
WSGIScriptAlias / /var/www/jcapp/jcapp.wsgi
<Directory /var/www/jcapp/>
WSGIProcessGroup jcapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName mysite.co
Redirect 301 / http://www.mysite.co/
WSGIDaemonProcess jcapp
WSGIScriptAlias / /var/www/jcapp/jcapp.wsgi
<Directory /var/www/jcapp/>
WSGIProcessGroup jcapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
完成此配置后,我运行以下命令:
sudo a2ensite www.mysite.co.conf
sudo service apache2 restart
我收到以下错误:
Restarting web server apache2
The apache2 configtest failed.
Output of config test was:
AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/sites-enabled/www.mysite.co.conf:1
AH00526: Syntax error on line 27 of /etc/apache2/sites-enabled/www.mysite.co.conf:
Name duplicates previous WSGI daemon definition.
Action 'configtest' failed.
The Apache error log may have more information.
我检查了/var/log/apache2/error.log
并且它是空的。
有人可以告诉我在这里可能会错过什么吗?
答案 0 :(得分:0)
请在 /etc/apache2/sites-enabled/000-default.conf 的*:80块中写下重定向永久/ https://site.site.com 行如下所示。
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
redirect permanent / https://site.site.com
Alias /static /home/ubuntu/django_portal/ci/site_portal/portal_site/static
<Directory /home/ubuntu/django_portal/ci/site_portal/portal_site/static>
Require all granted
</Directory>
<Directory /home/ubuntu/django_portal/ci/site_portal/portal_site/go_portal_site>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
#WSGIDaemonProcess go_portal_site python-path=/home/ubuntu/django_portal/ci/site_portal/portal_site python-home=/home/ubuntu/django_portal/ci/site_portal/portal_site/phase2_env
WSGIProcessGroup go_portal_site
WSGIScriptAlias / /home/ubuntu/django_portal/ci/site_portal/portal_site/go_portal_site/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerName site.site.com
Alias /static /home/ubuntu/django_portal/ci/site_portal/portal_site/static
<Directory /home/ubuntu/django_portal/ci/site_portal/portal_site/static>
Require all granted
</Directory>
<Directory /home/ubuntu/django_portal/ci/site_portal/portal_site/go_portal_site>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess go_portal_site python-path=/home/ubuntu/django_portal/ci/site_portal/portal_site python-home=/home/ubuntu/django_portal/ci/site_portal/portal_site/phase2_env
WSGIProcessGroup go_portal_site
WSGIScriptAlias / /home/ubuntu/django_portal/ci/site_portal/portal_site/go_portal_site/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/site.site.com-cer.pem
SSLCertificateKeyFile /etc/apache2/ssl/site.site.com-key.pem