Score:0

Different ports are serving different SSL certificates

id flag

I have an nginx server with ssl set up using certbot. Someone else set up the server originally. The main files are served at the root of the domain, and there is a node api running on port 4040. The problem is that while the SSL certificate for the root domain works fine (eg. https://example.com/some/path), the SSL certificate for the api is expired (https://example.com:4040/api/route). I didn't even know it was possible to set up SSL this way and after looking over my nginx config, I don't know how it's behaving this way. Here is my nginx config (in /etc/nginx/sites-enabled/default)

server {
    root /var/www/myapp/current/dist;

    server_name example.com;

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

    location / {
      try_files $uri $uri/ /index.html;
    }
}

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


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

    server_name example.com;
    return 404; # managed by Certbot
}

Everything was working fine with this setup until the SSL cert being served at the :4040 port expired today. I'd like to get the certificate being served for the root domain to be served for the :4040 port as well, I'm just not sure how.

Score:0
id flag

I figured it out, and really should have caught this earlier. The node server that I'm running for the api handles serving the SSL certificate on it's own through the https module. Because the app didn't restart after the certificate was renewed by certbot, it was still serving the old certificate. Restarting the node app solved the problem.

The right way to handle this is to use a combination of --pre-hook and --post-hook with certbot's renew functionality. Because I'm managing my node app with pm2, I needed to update my certbot cron job to:

@monthly   /path/to/certbot-auto renew --standalone --post-hook "pm2 restart myapp"
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.