Home > Software engineering >  django nginx gunicorn issues with Cerbot to turn into HTTPS
django nginx gunicorn issues with Cerbot to turn into HTTPS

Time:01-24

I am currently deploying my django app on a server AWS Lightsail Debian 10.8. It's working fine with http. So I wnated to turn my app into HTTPS and getting an SSL certificate. I followed 2 tutorials about it :

Once all these steps done nothing works anymore even in HTTP, the site isn't accessible... Here is the config file in /etc/nginx/sites-available.

 server {
  server_name 13.38.76.96 www.zlochteam.com;

 location / {
        include proxy_params;
        proxy_pass http://localhost:8000/;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.zlochteam.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.zlochteam.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.zlochteam.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


  listen 80;
  server_name 13.38.76.96 www.zlochteam.com;
    return 404; # managed by Certbot


}

I wanted to know if someone has ecountered the same issue and how he solved it.

Thanks !

CodePudding user response:

Http has break because the certbot added the redirect return 301 https://$host$request_uri;

You should test config by command nginx -t and then reload config nginx -s reload.

CodePudding user response:

Before you run the commands in certbot, make sure you have the following in your Nginx:

server {
    listen 80;
    server_name 13.38.76.96 www.zlochteam.com;
    listen [::]:80;
    ...

Seems like certbot now requires the ipv6 as well.

  •  Tags:  
  • Related