Setting up Nginx.conf file

I am just looking for a little assistance in setting up my Nginx conf file. My site is digibrain.co and I currently have it running on http with these settings:

upstream backend {
    server backend:8000;
}

server {
    listen 80;
    server_name digibrain.co;

    location /.well-known/acme-challenge/ {
    root "/var/www/certbot";
    }

    location / {
        root "/var/www/frontend";
        try_files $uri $uri/ /index.html;
    }    

    location /api/ {
        proxy_pass http://backend;
        proxy_set_header Host $http_host;
    }

    location /admin/ {
        proxy_pass http://backend;
        proxy_set_header Host $http_host;
    }
    
    location /static/ {        
        alias /backend/static/;
    }
}

I am thinking that I should be adding something like this but I am not sure:

server {
    listen 443 ssl;
    server_name digibrain.co;
    
    location / {
        proxy_pass http://digibrain.co; 
    }

    ssl_certificate /etc/letsencrypt/live/digibrain.co/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/digibrain.co/privkey.pem;

    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

I already have certs on the server and the system is using docker-compose (not that it should matter).

All help is appreciated. Thanks!

Fwiw this is a simple Django/React setup but my first time using Nginx and Docker. Nginx won't seem to start up when I add the second server code block for ssl so it must be wrong.

What is the nginx error message?

2 Likes

Where is that supposed to get content from?

The port 80 server {} block should only be a redirect to HTTPS. The port 443 server {} block should incorporate all the old stuff of the port 80 server block, but now with added SSL directives.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.