Let's Encrypt - certbot / Nginx port conflict

I’m running nginx in Docker.
I managed to get Let’s Encrypt certificates via certbot.

sudo certbot certonly --nginx -d my.domain.de

To get the certificates I had to stop the Nginx container, because it uses ports 80 & 443.
After getting the certificates the container didn’t start because a process nginx blocked both ports. After killing these processes, the container started again.
But now the certificate renewal is not working because the Nginx container blocks the ports.

How can I solve this issue?

1 Like

This is what I would do:

Map the Let’s Encrypt certificate directory into your Nginx container:

volumes:
  - /etc/letsencrypt:/etc/letsencrypt

Update your Nginx configuration to use these paths:

ssl_certificate /etc/letsencrypt/live/my.domain.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/my.domain.de/privkey.pem;

Set up certbot to use the webroot plugin instead of the nginx plugin:

certbot renew --webroot -w /path/to/webroot
1 Like

Thanks, will try it