Django 1.8 App在添加SSL时显示文件夹结构

时间:2015-12-28 13:02:26

标签: django apache ubuntu ssl

我的网站正在开发http

我现在希望它能够使用SSl证书。我已经生成了密钥并设置了虚拟主机:

<VirtualHost *:80>
        WSGIDaemonProcess pms python-path=/home/ubuntu/myapp/myapp:/home/ubuntu/myapp/env/lib/python3.4$
        WSGIProcessGroup myapp
        WSGIScriptAlias / /home/ubuntu/myapp/myapp/myapp/wsgi.py

        <Directory /home/ubuntu/myapp/myapp/myapp>
            <Files wsgi.py>
                Require all granted
            </Files>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>

        ServerAdmin support@myapp.com
</VirtualHost>

<VirtualHost *:443>
    SSLEngine On
    SSLCertificateFile /etc/apache2/ssl/ca.crt
    SSLCertificateKeyFile /etc/apache2/ssl/ca.key

    ServerName leanhotelsystem.com
    ServerAlias *.leanhotelsystem.com
    DocumentRoot /home/ubuntu/myapp/myapp/myapp

    <Directory /home/ubuntu/myapp/myapp/myapp>
        <Files wsgi.py>
            Require all granted
        </Files>

        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ServerAdmin support@myapp.com

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost> 

我也设置了wsgi.py:

os.environ['HTTPS'] = "on"

并在settings.py中:

WSGI_APPLICATION = 'myapp.wsgi.application'
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

问题是,当我使用https访问网址时,它会显示我的文件夹结构,而不是呈现主页。 如果我通过http访问它可以正常工作。

谢谢!

1 个答案:

答案 0 :(得分:0)

您似乎忘记了新VirtualHost中的WSGI设置部分。