带有反向代理后面的HTTPS的build_absolute_uri

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带有反向代理后面的HTTPS的build_absolute_uri相关的知识,希望对你有一定的参考价值。

我正在反向代理后面提供我的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.

以上是关于带有反向代理后面的HTTPS的build_absolute_uri的主要内容,如果未能解决你的问题,请参考以下文章

如何在带有 SSL 的 nginx 反向代理后面正确运行 BeEF

在反向代理后面使用 OAuth2 的 Spring Boot

在带有协议升级的 nginx 反向代理后面运行 daphne 总是路由到 http 而不是 websocket

带有 SNI 的 Apache HTTPS 反向代理,代理上没有密钥

带有 url 重写的 HTTPS 反向代理

代理后面的TYPO3生成与http而不是https的绝对链接