我正在尝试使用NGINX反向代理服务器部署django应用程序。
我的/etc/nginx/conf.f/app.conf
看起来像这样:
server {
listen 80;
listen 443 ssl;
server_name myhost.com;
ssl_certificate /etc/letsencrypt/live/myhost.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/myhost.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
当我打开myhost.com时,我得到浏览器的ERR_TOO_MANY_REDIRECTS
错误。我不知道如何解决它,但如果我重写http://127.0.0.1:8000
为https://127.0.0.1:8000
,我得到502 Bad Gateway
错误。
Django正在听:http://127.0.0.1:8000。
我认为这与URL中的尾部斜杠有关。
尝试换行
proxy_pass http://127.0.0.1:8000;
至
proxy_pass http://127.0.0.1:8000/;
这可能会解决问题
在settings.py
,设置SECURE_SSL_REDIRECT = False
。