Trouble getting certificates for Mac and nginx

I tried to follow these instructions: Certbot Instructions | Certbot to get certs but I am having trouble getting certificates on my Mac

My domain is: I don't think this info is relevant yet

I ran this command: sudo certbot certonly --nginx

It produced this output:
Error while running nginx -c /usr/local/etc/nginx/nginx.conf -t.

nginx: [emerg] open() "/usr/local/etc/nginx/nginx.conf" failed (2: No such file or directory)

nginx: configuration file /usr/local/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 /usr/local/etc/nginx/nginx.conf -t.\n\nnginx: [emerg] open() "/usr/local/etc/nginx/nginx.conf" failed (2: No such file or directory)\nnginx: configuration file /usr/lo

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

The operating system my web server runs on is (include version): Monterey vs 12.0.1

I can login to a root shell on my machine: yes

The version of my client is: certbot 1.22.0

I assume the issue is that nginx is actually installed here on my Mac: /opt/homebrew/etc/nginx
but certbox keeps looking here instead: /usr/local/etc/nginx

How do I get certbot look in the right location instead? thanks

1 Like

You could try using the --nginx-server-root and, if necessary, --nginx-ctl option(s). See User Guide — Certbot 1.22.0 documentation for more info.

5 Likes

Yes. For nginx from Homebrew, this works on my M1 Mac:

--nginx-server-root $HOMEBREW_PREFIX/etc/nginx/
6 Likes

OR
Avoid using --nginx altogether, and use --webroot instead.
[unless you need certbot to "install" the cert (and create the secured vhost for you)]

3 Likes

thanks! yes using --nginx-server-root solved this particular issue

4 Likes

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