build_absolute_uri с HTTPS за обратным прокси - PullRequest
0 голосов
/ 27 мая 2020

Я обслуживаю свое приложение django через обратный прокси-сервер

Inte rnet -> Nginx -> Сокет Gunicorn -> Django app

В nginx config:

upstream my_server {
  server unix:/webapps/my_app/run/gunicorn.sock fail_timeout=0;
}

SSL настроен с помощью certbot на уровне nginx.

request.build_absolute_uri в views.py генерирует HTTP-ссылки. Как я могу заставить его генерировать https-ссылки?

1 Ответ

0 голосов
/ 27 мая 2020

Здесь есть примечание в документации 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.

...