Skip to content

fix: disable hosts and prevent nginx crash when certificate is deleted#5732

Open
mrbaloghakos wants to merge 2 commits into
NginxProxyManager:developfrom
mrbaloghakos:fix/cert-delete-nginx-offline
Open

fix: disable hosts and prevent nginx crash when certificate is deleted#5732
mrbaloghakos wants to merge 2 commits into
NginxProxyManager:developfrom
mrbaloghakos:fix/cert-delete-nginx-offline

Conversation

@mrbaloghakos

@mrbaloghakos mrbaloghakos commented Jul 22, 2026

Copy link
Copy Markdown

When a certificate is deleted in NPM, the nginx config files for proxy hosts using that certificate were left referencing cert files that no longer exist on disk. This caused nginx to refuse to start on the next restart with:

  nginx: [emerg] cannot load certificate ".../fullchain.pem": BIO_new_file()
  failed (SSL: error:80000002:... No such file or directory)

Two complementary fixes:

  1. certificate.delete() now finds all enabled hosts that reference the deleted certificate, removes their nginx config files, sets meta.nginx_online=false with nginx_err='Certificate was deleted', and reloads nginx. Hosts are taken fully offline (rather than silently downgraded to HTTP) so the user sees a clear signal in the UI.

  2. A new prepare script (55-nginx-validate.sh) runs before nginx starts and scans all host config files for ssl_certificate directives. Any config that references a cert file missing from disk is renamed to .conf.err so nginx never attempts to load it. This acts as a safety net for scenarios where cert files go missing without NPM knowing (volume recreation, manual deletion, etc.).

Also adds a Cypress test that verifies a proxy host is taken offline when its certificate is deleted.

ℹ️ Vibecoded using Claude Sonnet 4.6

Fixes the following issues:

Why

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • API changes
  • Performance improvement
  • Test addition or update

AI Usage

  • AI was used to write this (Claude Sonnet 4.6)
  • AI was used to review this

…eleted

When a certificate is deleted in NPM, the nginx config files for proxy hosts
using that certificate were left referencing cert files that no longer exist on
disk. This caused nginx to refuse to start on the next restart with:

  nginx: [emerg] cannot load certificate ".../fullchain.pem": BIO_new_file()
  failed (SSL: error:80000002:... No such file or directory)

Two complementary fixes:

1. certificate.delete() now finds all enabled hosts that reference the deleted
   certificate, removes their nginx config files, sets meta.nginx_online=false
   with nginx_err='Certificate was deleted', and reloads nginx. Hosts are taken
   fully offline (rather than silently downgraded to HTTP) so the user sees a
   clear signal in the UI.

2. A new prepare script (55-nginx-validate.sh) runs before nginx starts and
   scans all host config files for ssl_certificate directives. Any config that
   references a cert file missing from disk is renamed to .conf.err so nginx
   never attempts to load it. This acts as a safety net for scenarios where
   cert files go missing without NPM knowing (volume recreation, manual
   deletion, etc.).

Also adds a Cypress test that verifies a proxy host is taken offline when its
certificate is deleted.
The explicit DELETE /api/nginx/proxy-hosts cleanup at the end of the
'Deleting a certificate takes dependent proxy hosts offline' test was
causing a 502 in the MySQL CI environment. The double back-to-back
nginx reload (cert deletion + proxy host deletion) caused the backend
to become temporarily unreachable, failing the test.

The cleanup is unnecessary: every test spec's before() already calls
cy.resetUsers() which wipes all data before the next spec runs.
@nginxproxymanagerci

Copy link
Copy Markdown

Docker Image for build 2 is available on DockerHub:

nginxproxymanager/nginx-proxy-manager-dev:pr-5732

Note

Ensure you backup your NPM instance before testing this image! Especially if there are database changes.
This is a different docker image namespace than the official image.

Warning

Changes and additions to DNS Providers require verification by at least 2 members of the community!

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

Successfully merging this pull request may close these issues.

1 participant