Ghost installation fails because nginx cant be restarted - how do I fix this?

Hi,

I am attempting to install ghost, but it keeps failing because nginx can not be restarted, due to an error (with the letsencrypt certs I think).

How can I get this working?

System Information:

OS: Ubuntu, v22.04.2 LTS
Node Version: v16.19.1
Ghost Version: 5.38.0
Ghost-CLI Version: 1.24.0

Debug Information:


    Environment: production
    Command: 'ghost install'
Message: Failed to restart Nginx.
Stack: Error: Failed to restart Nginx.
    at NginxExtension.restartNginx (/usr/lib/node_modules/ghost-cli/extensions/nginx/index.js:262:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Original Error Message:
Message: Command failed: /bin/sh -c sudo -S -p '#node-sudo-passwd#'  nginx -s reload
nginx: [emerg] cannot load certificate "/etc/letsencrypt/jaytelford.me/fullchain.cer": BIO_new_file() failed (SSL: error:80000002:system library::No such file or directory:calling fopen(/e
tc/letsencrypt/jaytelford.me/fullchain.cer, r) error:10000080:BIO routines::no such file)


Stack: Error: Command failed: /bin/sh -c sudo -S -p '#node-sudo-passwd#'  nginx -s reload
nginx: [emerg] cannot load certificate "/etc/letsencrypt/jaytelford.me/fullchain.cer": BIO_new_file() failed (SSL: error:80000002:system library::No such file or directory:calling fopen(/e
tc/letsencrypt/jaytelford.me/fullchain.cer, r) error:10000080:BIO routines::no such file)


    at makeError (/usr/lib/node_modules/ghost-cli/node_modules/execa/index.js:174:9)
    at /usr/lib/node_modules/ghost-cli/node_modules/execa/index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async NginxExtension.restartNginx (/usr/lib/node_modules/ghost-cli/extensions/nginx/index.js:260:13)

...

The journal for nginx says this:

░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ An ExecStartPre= process belonging to unit nginx.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 1.
Mar 11 14:38:57 zod.jaytelford.me systemd[1]: nginx.service: Failed with result 'exit-code'.
░░ Subject: Unit failed

I attempted to uninstall ghost, but that command would not work either - so I manually trashed the directory, deleted all the letsencrypt certificates manually, removed the server configurations from nginx manually, and started nginx.

I then went through the installation process again, which failed with the same errors.

How can I fix this and get it to work?

Thanks

Jay

Welcome to the Ghost community, @jgtelford.

Nginx won’t start because you have created an error state by deleting Let’s Encrypt certificates manually. This is the wrong way to go about this, and has resulted in Nginx not locating referenced files.

Moreover, you risk hitting a rate limit with Let’s Encrypt if you make too many repeated requests. Indeed, this may have been the original issue.

Ideally, restore a snapshot or backup, to return to a known good state. However, this will not help whether you have hit a rate limit or have deleted your private key.

Thank you for your reply.

Sadly, I did not make a backup before I began installing Ghost, and it has been quite some time since I used it last, meaning my last backup is very old.

This is a lesson about making regular backups and not manually deleting stuff.

Since I can not restore the server to a backup, if I purge nginx and certbot from the system, and then reinstall it so that all configuration files are reset back to “factory” default, will that also work?

I will wait a day or two before trying again as well, to try and avoid the letsencrypt rate limit.

Thanks

Removing Nginx should be fairly straightforward; sudo apt remove --purge nginx and then remove /etc/nginx.

However, removing certbot is probably not so easy. Since I don’t use it anymore, I can’t offer much assistance, but I’d probably use dpkg to list what’s installed first, and then look for letsencrypt entries elsewhere.

Once sorted, you may find that you won’t be issued certificates for a few days or so. Therefore, read the documentation, and use the test options while setting up your domain.

Alternatively, consider using Cloudflare. If you do this, skip SSL and Nginx when installing Ghost.

Hello, I am having the same questions. Could you come up with a more detailed solution?