Home > Back-end >  (Django / Nginx / Gunicorn) HTTPS fails to serve pathed directories on my site
(Django / Nginx / Gunicorn) HTTPS fails to serve pathed directories on my site

Time:10-06

Pretty new to Nginx and web deployment in general. I have a site I am aiming to deploy using a DigitalOcean droplet. Right now it is working, but only with http://[SERVER-IP] (here)

Although the site does load with HTTPS (here), no domain.com/[ X ] sites work.

The aim is to make get all URLs within https://rejesto.com functioning normally and leading to their respective sites.

For context, all links on the page are provided by Djagno's {% url '[url]' %} tag system; they work as intended locally, and using http://[SERVER-IP]/[ X ].


I'm assuming that the issue is within the Nginx config files because:

  1. http://46.101.92.95/blog leads to the correct page. (for better or for worse)
  2. https://rejesto.com/blog does not work.

Here is (what I believe to be) the relevant config file:

/etc/nginx/sites-available/rejesto.com:

server {

   server_name rejesto.com www.rejesto.com;
   location / {
        try_files $uri $uri/ =404;
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/rejesto/myprojectdir;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot                                                   
    ssl_certificate /etc/letsencrypt/live/rejesto.com/fullchain.pem; # managed by Certbot  
    ssl_certificate_key /etc/letsencrypt/live/rejesto.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                    
                                                                                           
} 

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


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


    listen 80;
    listen [::]:80;

    server_name rejesto.com www.rejesto.com;

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }

    return 404; # managed by Certbot

}


server {

    listen 80;
    server_name 46.101.92.95;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/rejesto/myprojectdir;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}


For additional context, I was following these tutorials provided by Digital Ocean:

CodePudding user response:

Your nginx configuration is incorrect.

  1. Uninstall certbot and remove all the certificates.

  2. Use this nginx configuration:

    server {
        listen 80;
        listen [::]:80;
        server_name www.rejesto.com;
        return 301 $scheme://rejesto.com$request_uri;
     }
    server {
        listen 80;
        listen [::]:80;
        server_name rejesto.com;
        location = /favicon.ico { access_log off; log_not_found off; }
        location /static/ {
             root /home/rejesto/myprojectdir;
         }
         location / {
              include proxy_params;
              proxy_pass http://unix:/run/gunicorn.sock;
         }
     }
    
     server {
         listen 80;
         server_name 46.101.92.95;
    
         location = /favicon.ico { access_log off; log_not_found off; }
         location /static/ {
         root /home/rejesto/myprojectdir;
         }
    
         location / {
             include proxy_params;
             proxy_pass http://unix:/run/gunicorn.sock;
         }
     }
    
  3. Initialise nginx:

    sudo nginx -t
    sudo systemctl restart nginx

  4. Reinstall certbot and issue your certificates.

CodePudding user response:

'settings django: ALLOWED_HOSTS = ['exemple.com','ip']

Dns pointe vers le domaine ? 

systemctl restart gunicorn 
systemctl restart nginx

proxy_pass http://unix:/var/run/gunicorn.sock'
  • Related