Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从非www重定向到www不工作Apache2_Python_Apache_Redirect_Flask - Fatal编程技术网

Python 从非www重定向到www不工作Apache2

Python 从非www重定向到www不工作Apache2,python,apache,redirect,flask,Python,Apache,Redirect,Flask,我试图按照这个答案中的第一种方法将我的网站mysite.com重定向到www.mysite.com。该站点正在使用Flask和Python 2.7.6,运行在Ubuntu 14.04上 下面是它的配置(文件名:www.mysite.co.conf): 我检查了/var/log/apache2/error.log,它是空的 有人能告诉我这里遗漏了什么吗?请在*80块/etc/apache2/sites enabled/000 default.conf中写一行重定向永久/,如下所示 <Virt

我试图按照这个答案中的第一种方法将我的网站mysite.com重定向到www.mysite.com。该站点正在使用Flask和Python 2.7.6,运行在Ubuntu 14.04上

下面是它的配置(文件名:www.mysite.co.conf):

我检查了
/var/log/apache2/error.log
,它是空的


有人能告诉我这里遗漏了什么吗?

请在*80块/etc/apache2/sites enabled/000 default.conf中写一行重定向永久/,如下所示

<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

服务器管理员webmaster@localhost
DocumentRoot/var/www/html
重定向永久/https://site.site.com
别名/static/home/ubuntu/django\u门户/ci/site\u门户/portal\u站点/static
要求所有授权
要求所有授权
#WSGIDaemonProcess go\u portal\u site python path=/home/ubuntu/django\u portal/ci/site\u portal/portal\u site python home=/home/ubuntu/django\u portal/ci/site\u portal\u site/phase2\u env
WSGIProcessGroup go_门户网站
WSGIScriptAlias//home/ubuntu/django_portal/ci/site_portal/portal_site/go_portal_site/wsgi.py
ErrorLog${APACHE_LOG_DIR}/error.LOG
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
ServerName site.site.com
别名/static/home/ubuntu/django\u门户/ci/site\u门户/portal\u站点/static
要求所有授权
要求所有授权
WSGIDaemonProcess go\u portal\u site python path=/home/ubuntu/django\u portal/ci/site\u portal/portal\u site python home=/home/ubuntu/django\u portal/ci/site\u portal\u site/phase2\u env
WSGIProcessGroup go_门户网站
WSGIScriptAlias//home/ubuntu/django_portal/ci/site_portal/portal_site/go_portal_site/wsgi.py
ErrorLog${APACHE_LOG_DIR}/error.LOG
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
斯伦金安
SSLCertificateFile/etc/apache2/ssl/site.site.com-cer.pem
SSLCertificateKeyFile/etc/apache2/ssl/site.site.com-key.pem

正如错误所述,您有重复的名称。为什么要在两个独立的虚拟主机中执行此操作?但是这两个虚拟主机中的
ServerName
是不同的。我在书中读到了一些关于这种方法的答案,而不是使用.htaccess,顺便说一句,它不起作用,导致我寻找另一种方法。一个这样的答案在问题的第一行链接。
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.
<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