我正在反向代理后面提供我的Django应用程序
互联网-> Nginx-> Gunicorn套接字-> Django应用
在Nginx配置中:
upstream my_server {
server unix:/webapps/my_app/run/gunicorn.sock fail_timeout=0;
}
使用certbot在nginx级别上设置SSL。
request.build_absolute_uri
中的[views.py
]生成http链接。如何强制它生成https链接?
django文档中https://docs.djangoproject.com/en/3.0/ref/request-response/#django.http.HttpRequest.build_absolute_uri中有一条注释:
Mixing HTTP and HTTPS on the same site is discouraged, therefore build_absolute_uri() will always generate an absolute URI with the same scheme the current request has. If you need to redirect users to HTTPS, it’s best to let your Web server redirect all HTTP traffic to HTTPS.