[英]Django urls with https behind nginx proxy
我在nginx proxy和vue js的某些前端后面有django rest框架。 问题是我的网址带有“ http”,但我需要将其设为“ https”:
"images": [
{
"id": 2,
"image": "http://localhost:8000/media/documents/2019/02/26/d59b9c8d-bb36-4461-97ad-7455f19637b8/FVbJkfww_Sk.jpg"
},
{
"id": 1,
"image": "http://localhost:8000/media/documents/2019/02/26/902e5729-f7fd-480b-bf39-bca65a83038e/%D0%B4%D0%B6%D0%B5%D0%BA%D0%B8-%D1%87%D0%B0%D0%BD-%D0%BC%D0%B5%D0%BC-%D1%88%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD.jpg"
}
]
nginx的配置如下:
server {
listen 8443 ssl;
server_name backend.mysite.net;
client_max_body_size 3200m;
proxy_connect_timeout 3000;
proxy_send_timeout 3000;
proxy_read_timeout 3000;
send_timeout 3000;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8000;
}
我的Django配置操作系统如下:
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_SSL_REDIRECT = True
USE_X_FORWARDED_HOST = True
这是因为丢失proxy_set_header X-Forwarded-Proto https
在您的location
更新到
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https
proxy_pass http://localhost:8000;
}
如果那不起作用,请尝试
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https
proxy_redirect off;
proxy_pass http://localhost:8000;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.