静态文件Django不与Certifield一起运行让我们加密

时间:2018-10-21 02:42:19

标签: python django nginx lets-encrypt certbot

我有一个带有django框架的python网站。在服务器上,我将NGINX和Supervisor用于Gunicorn。

NGINX提供的静态文件没有Let's Encrypt证书。但是,当我把它放进去之后,静态文件就不再提供了。

我该怎么办?

------ NGINX设置------

#upstream mysite{ server 127.0.0.1:8000 fail_timeout=0; }
server {
client_max_body_size 4G;
server_name mysite.net www.mysite.net;
access_log /var/log/nginx/mysite.access.log;
error_log /var/log/nginx/mysite.error.log;

location /static/ {
    alias /home/dev/sites/mysite/mysite/static/;
}
location /media/ {
     alias /home/dev/sites/mysite/mysite/media/;
}
location / {
    try_files $uri @proxy_to_app;
}
location @proxy_to_app {
    proxy_pass http://127.0.0.1:8000;
}

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.net/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
}

server {
if ($host = www.mysite.net) {
return 301 https://$host$request_uri;
} # managed by Certbot

if ($host = mysite.net) {
return 301 https://$host$request_uri;
} # managed by Certbot

server_name mysite.net www.mysite.net;
listen 80;
return 404; # managed by Certbot
}

0 个答案:

没有答案