Nginx, multiple server blocks

Okay so I have nginx config that looks something like this:
server {
root /var/www/frontend/dist;

            index index.html index.htm index.nginx-debian.html;

            server_name bankofsoftware.com www.bankofsoftware.com;

            location / {             
                    try_files $uri $uri/ =404;
            }

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

        location / {
            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    }

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


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


            listen 80 default_server;
            listen [::]:80 default_server;

            server_name bankofsoftware.com www.bankofsoftware.com;
        return 404; # managed by Certbot
    }

As you can see, I have another server block for my app subdomain. Now my questions is can I run the same certbot command (just replace the domain parameters with my subdomain) and will nginx just add stuff to my cofig or what should I do in order to get it to work too ?

Hi,

Certbot create another server block @ port 443 because you haven't had one. (Also you choose to let certbot enable the redirection as well as add keys)

If you want to let certbot manage your Nginx 443 config (https/ssl config): Yes, proceed on.

If you want to create the server block by yourself, please create a server block that has your subdomain and port then use certbot (as it will add keys and redirection)

In short, just run the command (for the subdomain) and you'll get the 443 auto-config by certbot.

Thank you

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