【发布时间】:2018-12-12 01:04:40
【问题描述】:
我有一个运行 Python/Django/uWSGI/Nginx 设置的网站。我还使用 Certbot 在我的网站上启用 https。我从非 www 到 www 的重定向(例如“example.com”到“www.example.com”)会导致“错误请求(400)”消息,即使我无法发现与 Nginx/Certbot 文档的任何偏差.这是我的sites-available Nginx 代码的相关部分:
server {
listen 80;
server_name example.com www.example.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/myname/example;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/activities.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; #managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; #managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
if ($scheme != "https") {
return 301 https://$host$request_uri;
} # managed by Certbot
}
我找到了一个类似的 StackOverflow 答案 (Nginx: redirect non-www to www on https),但没有一个解决方案适合我。我有 example.com 和 www.example.com 的 SSL 证书。我还尝试根据该答案中的 cmets 为 example.com 创建一个单独的 443 ssl 服务器块,但它也不起作用。我的sites-available 和sites-enabled 代码是一样的。
我做错了什么?
【问题讨论】:
-
“不工作”是什么意思?
-
我收到“错误请求 (400)”错误。我将编辑原始评论以包含它。
标签: django ssl nginx https url-redirection