fix: add NGINX_PORT_IN_REDIRECT var and document NGINX_X_FORWARDED_PORT#417
Open
fix: add NGINX_PORT_IN_REDIRECT var and document NGINX_X_FORWARDED_PORT#417
Conversation
Move port_in_redirect to the http block in nginx.conf.template, controlled by a new NGINX_PORT_IN_REDIRECT env var (default: off). This ensures the setting applies globally to all server blocks, including custom templates mounted by users, fixing the issue where custom default.conf.template replacements reverted to nginx's port-including redirect behavior. Also adds NGINX_X_FORWARDED_PORT to the README env vars table, which was previously undocumented despite being available in both Dockerfiles. Closes #407 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Updates the nginx-based image templates to make port_in_redirect configurable globally via a new NGINX_PORT_IN_REDIRECT env var, and documents the existing NGINX_X_FORWARDED_PORT variable.
Changes:
- Move
port_in_redirectconfiguration from per-server blocks to the globalhttpblock innginx.conf.template, controlled byNGINX_PORT_IN_REDIRECT. - Remove hardcoded
port_in_redirect off;fromdefault.conf.templateserver blocks. - Add
NGINX_PORT_IN_REDIRECT=offdefaults in both Debian and Alpine nginx Dockerfiles and documentNGINX_PORT_IN_REDIRECT+NGINX_X_FORWARDED_PORTin the README.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| nginx/templates/nginx.conf.template | Adds global port_in_redirect directive controlled by NGINX_PORT_IN_REDIRECT. |
| nginx/templates/conf.d/default.conf.template | Removes per-server port_in_redirect off; now that it’s configured globally. |
| nginx/Dockerfile-alpine | Defines default NGINX_PORT_IN_REDIRECT=off for Alpine variant. |
| nginx/Dockerfile | Defines default NGINX_PORT_IN_REDIRECT=off for Debian variant. |
| README.md | Documents NGINX_X_FORWARDED_PORT, adds NGINX_PORT_IN_REDIRECT, and updates the breaking-change note accordingly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NGINX_PORT_IN_REDIRECT(default:off) to control nginx'sport_in_redirectdirective, moving it from per-server blocks indefault.conf.templateto thehttpblock innginx.conf.template— so it applies globally including to custom server templates users mountNGINX_X_FORWARDED_PORTenv var in the README table alongsideNGINX_X_FORWARDED_PROTOport_in_redirectbreaking-change notice to reference the new variable and explain how to restore the old behavior (NGINX_PORT_IN_REDIRECT=on)Closes #407
Test plan
port_in_redirect offappears in the renderednginx.confNGINX_PORT_IN_REDIRECT=onand verifyport_in_redirect onappears in the rendered config/address) redirects without the internal port in theLocationheader when behind a reverse proxy🤖 Generated with Claude Code