Baptiste ZLOCH
Baptiste ZLOCH

Reputation: 72

django+nginx+gunicorn issues with Cerbot to turn into HTTPS

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 !

Upvotes: 2

Views: 1090

Answers (3)

Baptiste ZLOCH
Baptiste ZLOCH

Reputation: 72

Resolved

I just had to allow connection from the port 443 on AWS LightSail, such a dummy error...

Here is where you need to add the HTTPS connection, in the Networking tab.

AWS LightSail Networking part

Upvotes: 1

raphael
raphael

Reputation: 2880

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.

Upvotes: 2

Aleksey Vaganov
Aleksey Vaganov

Reputation: 501

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.

Upvotes: 1

Related Questions