gpt4 book ai didi

带有 uwsgi+nginx 的 Django 在 http 上服务,但是一旦我添加了 listen on 443 和 ssl on;不再工作了

转载 作者:太空宇宙 更新时间:2023-11-03 14:30:37 24 4
gpt4 key购买 nike

我正在尝试让我的网站上线,它在 http 上运行良好,但是什么时候使用 ssl 证书和 https 我在/etc/nginx/sites-available/drlandivar.conf 中添加监听 443 和 ssl on 它说不安全的连接。

(它的 3 个域,指向一个项目)

这是我的/etc/nginx/sites-available/drlandivar.conf

    upstream django {
server 0.0.0.0:8080;
}

server {
listen 80;
server_name drlandivar.com www.drlandivar.com;
return 301 https://drlandivar.com$request_uri;
}
server {
listen 80;
server_name doutorlandivar.com www.doutorlandivar.com;
return 301 https://doutorlandivar.com$request_uri;
}

server {
listen 80;
server_name doctorlandivar.com www.doctorlandivar.com;
return 301 https://doctorlandivar.com$request_uri;
}


server {
listen 443;
server_name drlandivar.com www.drlandivar.com;
charset utf-8;

client_max_body_size 75M; # adjust to taste

ssl on;
ssl_certificate /etc/nginx/ssl/drlandivar.com/server.crt;
ssl_certificate_key /etc/nginx/ssl/drlandivar.com/server.key;

location /media {
alias /opt/virtualenv/landivarpj/media;
}

location /static {
alias /opt/virtualenv/landivarpj/static;
}

location / {
include /opt/virtualenv/landivarpj/uwsgi_params;
proxy_pass https://django;
proxy_redirect off;
include proxy_params;
}
}

server {
listen 443;
server_name doutorlandivar.com www.doutorlandivar.com;
charset utf-8;

client_max_body_size 75M; # adjust to taste

ssl on;
ssl_certificate /etc/nginx/ssl/doutorlandivar.com/server.crt;
ssl_certificate_key /etc/nginx/ssl/doutorlandivar.com/server.key;

location /media {
alias /opt/virtualenv/landivarpj/media;
}

location /static {
alias /opt/virtualenv/landivarpj/static;
}

location / {
include /opt/virtualenv/landivarpj/uwsgi_params;
proxy_pass https://django;
proxy_redirect off;
include proxy_params;
}
}


server {
listen 443;
server_name doctorlandivar.com www.doctorlandivar.com;
charset utf-8;

client_max_body_size 75M; # adjust to taste

ssl on;
ssl_certificate /etc/nginx/ssl/doctorlandivar.com/server.crt;
ssl_certificate_key /etc/nginx/ssl/doctorlandivar.com/server.key;

location /media {
alias /opt/virtualenv/landivarpj/media;
}

location /static {
alias /opt/virtualenv/landivarpj/static;
}

location / {
include /opt/virtualenv/landivarpj/uwsgi_params;
proxy_pass https://django;
proxy_redirect off;
include proxy_params;
}
}

我的/etc/nginx/proxy_params

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;

在我的 django 项目中,我有以下设置:

SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

我认为它在 proxy_params 或 proxy_pass 中有问题 https://django ;

问候

最佳答案

proxy_pass https://django ; # 这个设置可能是错误的。

普通的uwsgi服务用uwsgi协议(protocol)服务,可以用uwsgi_pass,一台服务器不需要upstream,upstream协议(protocol)可能有问题,肯定不是https。

你的url设置顺序也不对,nginx url匹配顺序是反的。我的英语不好,抱歉。

关于带有 uwsgi+nginx 的 Django 在 http 上服务,但是一旦我添加了 listen on 443 和 ssl on;不再工作了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52990551/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com