django 无法通过 HTTPS 使用 apache 和 mod_wsgi 运行
我的要求是通过 HTTPS 获取我的 django 应用程序。
我在命令的帮助下生成了 ssl 证书:
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout ssl_cert.key -out ssl_cert.crt
安装了 mod_wsgi 和 mod_ssl 并将它们配置到 httpd.conf 中:
SSLCertificateChainFile "location/to/certs/ssl_cert.cert"
WSGIScriptAlias / /location/to/django/app/wsgi.py
WSGIPythonHome /root/python3.9
#WSGIPythonPath "/root/python3.9/lib;/root/python3.9/lib/python3.9/site-packages"
WSGIPythonPath /location/to/django/app
<Directory /location/to/django/app>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
并重新启动了 apache 服务。
我在 settings.py 中进行了更改:
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
现在使用命令启动 Django 应用程序:
HTTPS=on python3 manage.py runserver 8000
它说:
Django version 2.2, using settings 'djangoApp.settings'
Starting development server at http://localhost:8000/
并且它仍然只能通过 http 访问,如果尝试通过 HTTPS 访问,它会给出错误:
This site can’t provide a secure connection
来自 debug.log:
You're accessing the development server over HTTPS, but it only supports HTTP.
有人可以帮忙吗?我缺少配置以及如何解决这个问题?
My requirement is to take my django app over HTTPS.
I generated ssl certs with the help of command:
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout ssl_cert.key -out ssl_cert.crt
Installed mod_wsgi and mod_ssl and configured them into httpd.conf as:
SSLCertificateChainFile "location/to/certs/ssl_cert.cert"
WSGIScriptAlias / /location/to/django/app/wsgi.py
WSGIPythonHome /root/python3.9
#WSGIPythonPath "/root/python3.9/lib;/root/python3.9/lib/python3.9/site-packages"
WSGIPythonPath /location/to/django/app
<Directory /location/to/django/app>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
And restarted apache service.
I made changes in settings.py as:
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
Now on starting Django App with command:
HTTPS=on python3 manage.py runserver 8000
It says:
Django version 2.2, using settings 'djangoApp.settings'
Starting development server at http://localhost:8000/
And its still accessible over http only and if trying to access over HTTPS, it gives error as:
This site can’t provide a secure connection
from debug.log:
You're accessing the development server over HTTPS, but it only supports HTTP.
Can somebody please help what I'm missing to configure and how to solve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论