Skip to content

fix(proxy): only reload nginx-proxy when its config test passes#494

Open
mrrobot47 wants to merge 1 commit into
EasyEngine:developfrom
mrrobot47:fix/nginx-reload-validate-config
Open

fix(proxy): only reload nginx-proxy when its config test passes#494
mrrobot47 wants to merge 1 commit into
EasyEngine:developfrom
mrrobot47:fix/nginx-reload-validate-config

Conversation

@mrrobot47

Copy link
Copy Markdown
Member

Problem

reload_global_nginx_proxy() gated the proxy reload on if ( \EE::launch( '... nginx -t' ) ). But EE::launch() defaults to returning a ProcessRun object (not an exit code), and every object is truthy in PHP — so the if was always true and the config was regenerated and reloaded regardless of whether nginx -t passed. A broken nginx config (e.g. from a half-written cert pair or a malformed vhost rule) was therefore reloaded and persisted; the shared proxy then fails to start on its next restart, taking down every site behind it.

Compounding bug: nginx -t also ran before the docker-gen regeneration, so it validated the pre-regeneration config rather than the default.conf that actually gets served.

Fix

Regenerate default.conf first, then capture the nginx -t ProcessRun and gate on 0 === $test->return_code. On failure, warn with the test output and skip the reload (return false); on success, reload. This mirrors the working nginx -t && nginx -s reload pattern already used elsewhere in the codebase.

Notes

  • Scope is this function's internal gate. The ~15 external callers that ignore the return value are unchanged; a skipped reload now returns false and emits an EE::warning, but wiring callers to react to that is a separate change.

Testing

Manual (needs the EE + Docker harness): introduce an invalid proxy config (bad cert/vhost), trigger a reload, and confirm it warns and does NOT reload/persist the broken config; with a valid config, confirm normal regenerate + reload.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

2 participants