我意识到有很多链接讨论这个主题,但到目前为止没有任何一个对我有用。我只想了解如何为我的项目启用 SSL 加密的明确步骤。
我的要求:应用程序的所有页面都需要使用“HTTPS”而不是“HTTP”。
我安装了 Bitnami djangostack-1.4.5-0,现在我正在我的本地主机端口 81 上进行开发,所以如果我也可以测试重定向,那将大有帮助。
我已经有一个虚拟证书,我在以下文件夹中使用其 key “myapp.key”创建了“myapp.crt” C:\BitNami\djangostack-1.4.5-0\apache2\conf
在那之后,我阅读的所有链接都混淆了我应该具体更改的地方。请帮忙!!并清楚更改的位置。
myapp folder structure:
django.wsgi
manage.py
MY_APP (folder)
|_ settings.py
|_ wsgi.py
|_ urls.py
|_ _init_.py
|_ apps (folder)
|_ static (folder)
|_ templates (folder)
最佳答案
我自己弄明白了这一点,并认为它可能对将来的人有所帮助。
1. Go to httpd.conf located in [BitNami_Installation]\djangostack-1.4.5-0\apache2\conf:
make sure the following is without # in front of it
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule ssl_module modules/mod_ssl.so
<IfModule ssl_module>
Include conf/extra/httpd-ssl.conf
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
2. Go to httpd-ssl.conf located in [BitNami_Installation]\djangostack-1.4.5-0\apache2\conf\extra
make sure the following is there
SSLCertificateFile "C:/BitNami/djangostack-1.4.5-0/apache2/conf/myapp.crt"
SSLCertificateKeyFile "C:/BitNami/djangostack-1.4.5-0/apache2/conf/myapp.key"
注意:证书和 key 是自己创建的
3. In settings.py
SESSION_COOKIE_SECURE= True
CSRF_COOKIE_SECURE=True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
暂时就这些,如果有其他参数需要调整会尝试添加。
关于django - 如何使用 Bitnami 为 django 应用程序启用 SSL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21085343/