Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

certbot instructions fail with ssl_certificate error on clean Ubuntu 20.04 LTS #940

Closed
brookmiles opened this issue May 1, 2022 · 9 comments

Comments

@brookmiles
Copy link
Contributor

brookmiles commented May 1, 2022

I followed the installation instructions pretty much to the letter, and the only hitch was the step "Acquiring a SSL certificate" which failed with the following error (actual host name was used, not example.com):

certbot --nginx -d example.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Error while running nginx -c /etc/nginx/nginx.conf -t.

nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directive in /etc/nginx/sites-enabled/mastodon:25
nginx: configuration file /etc/nginx/nginx.conf test failed

The nginx plugin is not working; there may be problems with your existing configuration.
The error was: MisconfigurationError('Error while running nginx -c /etc/nginx/nginx.conf -t.\n\nnginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directive in /etc/nginx/sites-enabled/mastodon:25\nnginx: configuration file /etc/nginx/nginx.conf test failed\n')

[Update Nov. 17 2022]

I was originally able to pass this step by following these instructions:

posted by @hughrun in #826 (comment)

But there's an even easier way, which also ensures that renewal will work correctly. As has been pointed out, using --standalone at the beginning will cause renewal to fail later because nginx will be running.

We want nginx to be running, but without the mastodon config loaded.

The best time to do this is before you copy the nginx configuration template and restart nginx, but if you're reading this, maybe you've already done that. Remove the link /etc/nginx/sites-enabled/mastodon to disable the mastodon config, and reload nginx.

By running certbot in certonly mode, we can use the nginx mode, renewals will work, and certbot won't mangle your config file.

  1. Run certbot certonly --nginx -d example.com
  2. Copy (or re-enable) the configuration template for nginx per the instructions
  3. Uncomment the ssl_certificate and ssl_certificate_key lines in /etc/nginx/sites-enabled/mastodon
  4. run nginx -t to test the config, and systemctl reload nginx to reload it
@plgonzalezrx8
Copy link

Thanks for this. Had the same issue and this solved my problem. I appreciate it.

@arananet
Copy link

Many thanks, @brookmiles, this save my day. Your instructions should be on the mastodon instructions as an additional tip. Here https://docs.joinmastodon.org/admin/install/, section, Acquiring a SSL certificate.

@sborrill
Copy link

As mentioned by @soletan, using --standalone will set the renewal authenticator to standalone. This will fail every time (runs twice a day by default) as standalone mode requires nginx to not be running. Fix is to edit /etc/letsencrypt/renewal/example.com.conf. Alter:
authenticator = standalone
to:

authenticator = nginx
installer = nginx

You can test with: certbot --force-renew renew

@Tron918-AdityaP
Copy link

@ brookmiles thank you for your solution, so simple and quick! (for others just a note: remember when you uncomment change the exmaple.com - your domain!)

@Beheadedstraw
Copy link

Beheadedstraw commented Dec 22, 2022

Another option is to:
systemctl stop nginx
certbot certonly --standalone -d domain.com
systemctl start nginx

@brookmiles
Copy link
Contributor Author

Another option is to: systemctl stop nginx certbot certonly --standalone -d domain.com systemctl start nginx

@Beheadedstraw As mentioned by others above, this will work manually, but will cause certbot to fail when it tries to automatically renew because nginx will be running.

@Beheadedstraw
Copy link

Another option is to: systemctl stop nginx certbot certonly --standalone -d domain.com systemctl start nginx

@Beheadedstraw As mentioned by others above, this will work manually, but will cause certbot to fail when it tries to automatically renew because nginx will be running.

Nevermind, didn't think about renewals, my bad on that one, one too many beers tonight XD

@stammy
Copy link

stammy commented Feb 26, 2023

@sborrill Thanks! Setting installer and authenticator to nginx in the fix you mentioned worked great for me.

@brookmiles
Copy link
Contributor Author

Fixed by #1036

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants