Could not find a usable 'nginx' binary

I can't issue certificates for source build nginx 1.24.

I have a hosting and source build nginx.

Certbot 2.8.0
Ubuntu 22.04
nginx/1.24.0 - compiled NGINX Open Source from source
Domain: ambientwhispersmedia.com
Hosting provider: Digital Ocean

I can login to a root shell on my machine: yes
I'm using a control panel to manage my site: no

I used instructions from nginx.com website: Installing NGINX Open Source | NGINX Documentation

Nginx configuration options:

./configure 
--user=nginx 
--group=nginx 
--with-pcre=../pcre2-10.42 
--with-zlib=../zlib-1.3 
--with-http_ssl_module 
--with-http_v2_module 
--with-stream 
--with-http_auth_request_module
--without-http_empty_gif_module
--add-module=../ngx_brotli

My paths to nginx files in the result:

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

======

STEP ONE - Everything is okey

snap install core
Result:
core 16-2.60.4 from Canonical✓ installed

snap refresh core
Result:
snap "core" has no updates available

snap install --classic certbot
Result:
certbot 2.8.0 from Certbot Project (certbot-eff✓) installed

ln -s /snap/bin/certbot /usr/bin/certbot

======

STEP TWO with errors

I am installing certbot to have SSL sertificate:

certbot --nginx -d ambientwhispersmedia.com -d www.ambientwhispersmedia.com

Error:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
The nginx plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError("Could not find a usable 'nginx' binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.")

Second try:

sudo certbot certonly --nginx -d ambientwhispersmedia.com -d www.ambientwhispersmedia.com

Error:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
The nginx plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError("Could not find a usable 'nginx' binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.")
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

Third try:

certbot certonly --nginx --nginx-server-root=/usr/local/nginx -d ambientwhispersmedia.com -d www.ambientwhispersmedia.com

Error:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
The nginx plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError("Could not find a usable 'nginx' binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.")
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

I asked for logs: tail /var/log/letsencrypt/letsencrypt.log

Output:

  File "/snap/certbot/3566/lib/python3.8/site-packages/certbot/_internal/main.py", line 1581, in certonly
    installer, auth = plug_sel.choose_configurator_plugins(config, plugins, "certonly")
  File "/snap/certbot/3566/lib/python3.8/site-packages/certbot/_internal/plugins/selection.py", line 256, in choose_configurator_plugins
    diagnose_configurator_problem("authenticator", req_auth, plugins)
  File "/snap/certbot/3566/lib/python3.8/site-packages/certbot/_internal/plugins/selection.py", line 374, in diagnose_configurator_problem
    raise errors.PluginSelectionError(msg)
certbot.errors.PluginSelectionError: The nginx plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError("Could not find a usable 'nginx' binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.")
2023-12-18 03:12:38,357:ERROR:certbot._internal.log:The nginx plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError("Could not find a usable 'nginx' binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.")

What shows?:
set | grep -i path=

My point is that if you typed "nginx -t" in any random location it would likely not find nginx.
Because, even though you compiled nginx [from source] on that system, the system itself is unaware of its' existence [globally].
If so, you might be able to place a symlink somewhere in your path to connect the [global] system to your current nginx location: "/usr/local/nginx/sbin/nginx"

3 Likes

Also, the --nginx plugin relies on standard paths by default. You may need to use the below settings for your config.

Or, use --webroot method instead. That does not need the tight interaction with the nginx server as the --nginx plugin requires

https://eff-certbot.readthedocs.io/en/latest/using.html#certbot-command-line-options

nginx:
Nginx Web Server plugin

--nginx-server-root NGINX_SERVER_ROOT
Nginx server root directory. (default: /etc/nginx or
/usr/local/etc/nginx)
--nginx-ctl NGINX_CTL
Path to the 'nginx' binary, used for 'configtest' and
retrieving nginx version number. (default: nginx)
--nginx-sleep-seconds NGINX_SLEEP_SECONDS
Number of seconds to wait for nginx configuration
changes to apply when reloading. (default: 1)

3 Likes

I've also used compiled versions of nginx.
But once complied, I generally just move that one single file to /usr/sbin/.

3 Likes

Add the nginx executable location to your PATH (and for any user running cerbot), so that you can just type nginx -v and it works.

Hi @max.mango.tango

Adding the location of the compiled binary to your path or moving it to the "/usr/sbin" should work.

Since this is not a distribution managed binary (you've compiled it from source), a better location for it would be under "/usr/local/sbin". Therefore, I would suggest to create a symlink for "/usr/local/nginx/sbin/nginx" under "/usr/local/sbin" which is (or should be) by default in your path:

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx

What I did:

1. Added PATH:

export PATH=$PATH:/usr/local/nginx/sbin

Now command nginx -t works in any folder.

2. I added link:

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx

3. What I tried:

certbot certonly --nginx -d ambientwhispersmedia.com -d www.ambientwhispersmedia.com

Output:

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

nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
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] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)\nnginx: configuration file /etc/nginx/nginx.conf test failed\n')
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

I tried start certbot with option --nginx-server-root and path /usr/local/sbin/nginx:

certbot certonly --nginx --nginx-server-root=/usr/local/sbin/nginx -d ambientwhispersmedia.com -d www.ambientwhispersmedia.com

Output:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Error while running nginx -c /usr/local/sbin/nginx/nginx.conf -t.

nginx: [emerg] open() "/usr/local/sbin/nginx/nginx.conf" failed (20: Not a directory)
nginx: configuration file /usr/local/sbin/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 /usr/local/sbin/nginx/nginx.conf -t.\n\nnginx: [emerg] open() "/usr/local/sbin/nginx/nginx.conf" failed (20: Not a directory)\nnginx: configuration file /usr/local/sbin/nginx/nginx.conf test failed\n')
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

I checked logs:

tail /var/log/letsencrypt/letsencrypt.log

Output:

  File "/snap/certbot/3566/lib/python3.8/site-packages/certbot/_internal/main.py", line 1581, in certonly
    installer, auth = plug_sel.choose_configurator_plugins(config, plugins, "certonly")
  File "/snap/certbot/3566/lib/python3.8/site-packages/certbot/_internal/plugins/selection.py", line 256, in choose_configurator_plugins
    diagnose_configurator_problem("authenticator", req_auth, plugins)
  File "/snap/certbot/3566/lib/python3.8/site-packages/certbot/_internal/plugins/selection.py", line 374, in diagnose_configurator_problem
    raise errors.PluginSelectionError(msg)
certbot.errors.PluginSelectionError: The nginx plugin is not working; there may be problems with your existing configuration.
The error was: MisconfigurationError('Error while running nginx -c /usr/local/sbin/nginx/nginx.conf -t.\n\nnginx: [emerg] open() "/usr/local/sbin/nginx/nginx.conf" failed (20: Not a directory)\nnginx: configuration file /usr/local/sbin/nginx/nginx.conf test failed\n')
2023-12-20 17:41:26,038:ERROR:certbot._internal.log:The nginx plugin is not working; there may be problems with your existing configuration.
The error was: MisconfigurationError('Error while running nginx -c /usr/local/sbin/nginx/nginx.conf -t.\n\nnginx: [emerg] open() "/usr/local/sbin/nginx/nginx.conf" failed (20: Not a directory)\nnginx: configuration file /usr/local/sbin/nginx/nginx.conf test failed\n')

I tried with option and path /usr/local/nginx/sbin/nginx:

certbot certonly --nginx --nginx-server-root=/usr/local/nginx/sbin/nginx -d ambientwhispersmedia.com -d www.ambientwhispersmedia.com

Output:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Error while running nginx -c /usr/local/nginx/sbin/nginx/nginx.conf -t.

nginx: [emerg] open() "/usr/local/nginx/sbin/nginx/nginx.conf" failed (20: Not a directory)
nginx: configuration file /usr/local/nginx/sbin/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 /usr/local/nginx/sbin/nginx/nginx.conf -t.\n\nnginx: [emerg] open() "/usr/local/nginx/sbin/nginx/nginx.conf" failed (20: Not a directory)\nnginx: configuration file /usr/local/nginx/sbin/nginx/nginx.conf test failed\n')
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

What else can I try?

My current path for nginx.conf: /usr/local/nginx/conf/nginx.conf

certbot is looking this nginx.conf here: /usr/local/nginx/sbin/nginx/nginx.conf, and not finding, which is correct.

How can I direct certbot to correct path?

The --nginx-server-root option is actually only used for looking up the configuration file, so you should set it to /usr/local/nginx/conf/.

4 Likes

Thank you!

The final command is:

certbot certonly --nginx --nginx-server-root=/usr/local/nginx/conf/ -d ambientwhispersmedia.com -d www.ambientwhispersmedia.com
2 Likes

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