Skip to content

fix: add NGINX_PORT_IN_REDIRECT var and document NGINX_X_FORWARDED_PORT#417

Open
fzipi wants to merge 1 commit intomainfrom
fix/nginx-x-forwarded-port-docs-and-http-level
Open

fix: add NGINX_PORT_IN_REDIRECT var and document NGINX_X_FORWARDED_PORT#417
fzipi wants to merge 1 commit intomainfrom
fix/nginx-x-forwarded-port-docs-and-http-level

Conversation

@fzipi
Copy link
Copy Markdown
Member

@fzipi fzipi commented Apr 25, 2026

Summary

  • Introduces NGINX_PORT_IN_REDIRECT (default: off) to control nginx's port_in_redirect directive, moving it from per-server blocks in default.conf.template to the http block in nginx.conf.template — so it applies globally including to custom server templates users mount
  • Documents the previously undocumented NGINX_X_FORWARDED_PORT env var in the README table alongside NGINX_X_FORWARDED_PROTO
  • Updates the port_in_redirect breaking-change notice to reference the new variable and explain how to restore the old behavior (NGINX_PORT_IN_REDIRECT=on)

Closes #407

Test plan

  • Build nginx Debian image and verify port_in_redirect off appears in the rendered nginx.conf
  • Build nginx Alpine image and verify the same
  • Set NGINX_PORT_IN_REDIRECT=on and verify port_in_redirect on appears in the rendered config
  • Confirm a request to a path without trailing slash (e.g. /address) redirects without the internal port in the Location header when behind a reverse proxy

🤖 Generated with Claude Code

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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_redirect configuration from per-server blocks to the global http block in nginx.conf.template, controlled by NGINX_PORT_IN_REDIRECT.
  • Remove hardcoded port_in_redirect off; from default.conf.template server blocks.
  • Add NGINX_PORT_IN_REDIRECT=off defaults in both Debian and Alpine nginx Dockerfiles and document NGINX_PORT_IN_REDIRECT + NGINX_X_FORWARDED_PORT in 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.

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.

Alpine image does not respect x-forwarded-port headers

2 participants