Supposed Nginx misconfiguration stops certbot from working

Please fill out the fields below so we can help you better. Note: you must provide your domain name to get help. Domain names for issued certificates are all made public in Certificate Transparency logs (e.g. crt.sh | example.com), so withholding your domain name here does not increase secrecy, but only makes it harder for us to provide help.

My domain is: themusthaves.co.uk

I ran this command: certbot --nginx -d themusthaves.co.uk

It produced this output: Saving debug log to /var/log/letsencrypt/letsencrypt.log
Error while running nginx -c /etc/nginx/nginx.conf -t.

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: configuration file /etc/nginx/nginx.conf test failed\n')

My web server is (include version): nginx version: nginx/1.25.4

The operating system my web server runs on is (include version): PRETTY_NAME="AlmaLinux 9.3 (Shamrock Pampas Cat)"

My hosting provider, if applicable, is: ANS (ans.co.uk)

I can login to a root shell on my machine (yes or no, or I don't know): yes

I'm using a control panel to manage my site (no, or provide the name and version of the control panel): no

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you're using Certbot): certbot 3.1.0

For about a year certbot worked fine on several servers we are hosting. Now from one moment to the next, about 4 weeks ago, certbot has stopped on all four machines. The four machines all have the same installations of Alma Linux, Nginx etc.

The thing is, when I run 'nginx -t' or 'service nginx reload' it works fine. I am quite sure there are no problems with the Nginx configuration.

Yet when I try to renew certbot certificates things fail. Things also fail when the daily cron runs to update the certificates. Certbot is installed with the appropriate nginx package and with snap.

Does anyone have an idea what the actual problem here can be?

Kind regards,

Sebastiaan

1 Like

Not yet but let's gather some more info. Would you show output of these

sudo nginx -c /etc/nginx/nginx.conf -t
sudo systemctl status -l --no-pager nginx
1 Like

I have added an attachment here so you can see I am not making things up. :stuck_out_tongue:

1 Like

What about this one? I was trying to confirm your nginx install matched the Certbot default selection.

I was also wanting to check if it was a new permissions problem by asking to see result w/sudo

1 Like

I added the output from the first command in the screenshot as well. To verify I will post the output again:

[root@i-d3757544 httpdocs]# sudo nginx -c /etc/nginx/nginx.conf -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

1 Like

Oh, sorry, missed it. And, does Certbot run as root ?

Was there any further error text? Maybe in the Certbot log? Searching for similar errors I usually see an explanation after the Misconfiguration line. Like this thread: I need help to install and config ssl certificate on my app

1 Like

I wished I could upload a txt file but it seems that is not possible. I added output of 'ps aux' as attachment. In this I am assuming that snapd is actually the user responsible to run certbot. Snapd is running as root.
output ps aux

Hereby the output of the /var/log/letsencrypt/letsencrypt.log for today:

2025-02-05 12:31:05,328:DEBUG:urllib3.connectionpool:http://localhost:None "GET /v2/connections?snap=certbot&interface=content HTTP/1.1" 200 97
2025-02-05 12:31:05,447:DEBUG:certbot._internal.main:certbot version: 3.1.0
2025-02-05 12:31:05,447:DEBUG:certbot._internal.main:Location of certbot entry point: /snap/certbot/4325/bin/certbot
2025-02-05 12:31:05,447:DEBUG:certbot._internal.main:Arguments: ['--nginx', '-d', 'themusthaves.co.uk', '--preconfigured-renewal']
2025-02-05 12:31:05,447:DEBUG:certbot._internal.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#apache,PluginEntryPoint#manual,PluginEntryPoint#nginx,PluginEntryPoint#null,PluginEntryPoint#standalone,PluginEntryPoint#webroot)
2025-02-05 12:31:05,467:DEBUG:certbot._internal.log:Root logging level set at 30
2025-02-05 12:31:05,467:DEBUG:certbot._internal.plugins.selection:Requested authenticator nginx and installer nginx
2025-02-05 12:31:05,475:ERROR:certbot.util:Error while running nginx -c /etc/nginx/nginx.conf -t.

nginx: configuration file /etc/nginx/nginx.conf test failed

2025-02-05 12:31:05,475:DEBUG:certbot._internal.plugins.disco:Misconfigured PluginEntryPoint#nginx: Error while running nginx -c /etc/nginx/nginx.conf -t.

nginx: configuration file /etc/nginx/nginx.conf test failed
Traceback (most recent call last):
File "/snap/certbot/4325/lib/python3.12/site-packages/certbot_nginx/_internal/configurator.py", line 1008, in config_test
util.run_script([self.conf('ctl'), "-c", self.nginx_conf, "-t"])
File "/snap/certbot/4325/lib/python3.12/site-packages/certbot/util.py", line 199, in run_script
raise errors.SubprocessError(msg)
certbot.errors.SubprocessError: Error while running nginx -c /etc/nginx/nginx.conf -t.

nginx: configuration file /etc/nginx/nginx.conf test failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/snap/certbot/4325/lib/python3.12/site-packages/certbot/_internal/plugins/disco.py", line 112, in prepare
self._initialized.prepare()
File "/snap/certbot/4325/lib/python3.12/site-packages/certbot_nginx/_internal/configurator.py", line 204, in prepare
self.config_test()
File "/snap/certbot/4325/lib/python3.12/site-packages/certbot_nginx/_internal/configurator.py", line 1010, in config_test
raise errors.MisconfigurationError(str(err))
certbot.errors.MisconfigurationError: Error while running nginx -c /etc/nginx/nginx.conf -t.

nginx: configuration file /etc/nginx/nginx.conf test failed

2025-02-05 12:31:05,476:DEBUG:certbot._internal.plugins.selection:Single candidate plugin: * nginx
Description: Nginx Web Server plugin
Interfaces: Authenticator, Installer, Plugin
Entry point: EntryPoint(name='nginx', value='certbot_nginx._internal.configurator:NginxConfigurator', group='certbot.plugins')
Initialized: <certbot_nginx._internal.configurator.NginxConfigurator object at 0x7fcc6493e570>
Prep: Error while running nginx -c /etc/nginx/nginx.conf -t.

nginx: configuration file /etc/nginx/nginx.conf test failed

1 Like

Ah, that's a good clue. Is it possible you have a mix of snap and non-stop nginx plugin?

Did you change from non-snap to snap about a month ago when this started failing?

That's about as far as my knowledge of Certbot packaging goes. If that's not enough for you to figure out what's wrong you'll have to wait for another volunteer. Maybe @Osiris ?

1 Like

Not sure what's going on. The code on that line 1008 isn't that difficult:

Did it work with previous versions of Certbot? Perhaps check if you have older versions of Certbot laying around with sudo snap list certbot and perhaps revert to an older version with sudo snap revert certbot --revision $revisionnumberofoldercertbot.

1 Like

Do you know where this comes from?

1 Like

Yeah, that's just because the MisconfigurationError from the code above propagates up the 'chain' of function calls and ultimately the code that tried to include the nginx plugin into the Certbot main application catches that MisconfigurationError in the code

and logs that error. That "PluginEntryPoint" is I guess something to ignore, it just says it was the nginx plugin that malfunctioned due to some kind of misconfiguration.

Too bad the output of util.run_script isn't included in the log.. As in, WHY did that command fail?

1 Like