Home > Enterprise >  nginx certbot doesnt redirect to django server
nginx certbot doesnt redirect to django server

Time:09-21

Im trying to set-up SSL sertificate for Django. I set up it by this guide: https://www.youtube.com/watch?v=dYdv6pkCufk&ab_channel=TonyTeachesTech, in the guide django server just start working with SSL, but for me is not working, but rederecting domain from http to https, but not redirecting to django server. I dont even know what to do. I search in entire internet and find nothing.

This is my nginx config:

server {
    listen 80 default_server;

    server_name _;

    return 301 https://$host$request_uri;
}
server {
    server_name wavera.ru www.wavera.ru; # managed by Certbot

    return 301 https://$host$request_uri;


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


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


    listen 80 ;
    server_name wavera.ru www.wavera.ru;
    return 404; # managed by Certbot




}


i starting server by

python3 manage.py runserver 

CodePudding user response:

Runserver is for development purposes only, You should run something like gunicorn to create a .sock file.

For now, you can try something like -

upstream backend {
    server localhost:8000;
}
server {
        server_name wavera.ru www.wavera.ru;
        location / {
            include proxy_params;
            proxy_pass http://backend 
     }

}

for https, try-

server {
        server_name wavera.ru www.wavera.ru;
           location / {
            include proxy_params;
               proxy_pass http://backend
        }
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.wavera.ru/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/www.wavera.ru/privkey.pem; 
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = wavera.ru) {
        return 301 https://$host$request_uri;
    }
    if ($host = www.wavera.ru) {
        return 301 https://$host$request_uri;
    }
    listen 80 ;
    server_name wavera.ru www.wavera.ru;
    return 404;
}
  • Related