StaticFiles Django not running with Certifield Let's Encrypt (Gunicorn + NGINX + Supervisor)


#1

Hello,

have a python site with the django framework. On the server I use NGINX and Supervisor for Gunicorn.

NGINX was serving static files without the Let’s Encrypt certificate. But after I put it in, the static files are not served.

What should I do?


#2

Can you provide more information?

What error message are you getting?

How is Nginx configured?


Please fill out the fields below so we can help you better. Note: you must provide your domain name to get help. Domain names for issued certificates are all made public in Certificate Transparency logs (e.g. https://crt.sh/?q=example.com), so withholding your domain name here does not increase secrecy, but only makes it harder for us to provide help.

My domain is:

I ran this command:

It produced this output:

My web server is (include version):

The operating system my web server runs on is (include version):

My hosting provider, if applicable, is:

I can login to a root shell on my machine (yes or no, or I don’t know):

I’m using a control panel to manage my site (no, or provide the name and version of the control panel):


#3

That’s the problem @mnordhoff . There is no error.
The problem is that you are not loading the still files with Certbot. But when the retreat, they are normally carried.

NGINX SETTINGS

#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_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    #proxy_set_header Host $http_host;
    #proxy_set_header X-Real-IP $remote_addr;
    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

location /static/ {
    alias /home/dev/sites/mysite/mysite/static/;
}
location /media/ {
    alias /home/dev/sites/mysite/mysite/media/;
}

}