Fix Traefik deployment: Replace SCRIPT_NAME with URL_PREFIX to avoid WSGI conflicts - #52
Merged
Merged
Conversation
Co-authored-by: tgangte <8805013+tgangte@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix Traefik configuration issue with Docker compose
Fix Traefik deployment: Replace SCRIPT_NAME with URL_PREFIX to avoid WSGI conflicts
Oct 16, 2025
tgangte
marked this pull request as ready for review
October 16, 2025 17:06
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.
Problem
When deploying LocalCA behind Traefik with path prefix stripping (e.g., serving at
/localca), users encounter this error:This prevents the application from working when deployed behind Traefik with the provided
docker-compose-traefik.ymlconfiguration.Root Cause
The issue stems from a conflict between Django's URL generation and WSGI's request path validation:
docker-compose-traefik.ymlsetsSCRIPT_NAME=/localcaas an environment variable/localcaprefix before forwarding requests to Django (as configured)/(after stripping)SCRIPT_NAMEfrom the environment and use it to validate incoming request pathsSCRIPT_NAME'/'does not start with'/localca'This is a fundamental incompatibility: you cannot use
SCRIPT_NAMEas an environment variable when the reverse proxy strips the prefix before forwarding requests.Solution
This PR introduces a new environment variable
URL_PREFIXto replaceSCRIPT_NAME:URL_PREFIXis a custom variable that doesn't interfere with WSGI's path validationFORCE_SCRIPT_NAMEsetting, which controls URL generation/localcaprefixChanges Made
os.environ.get('SCRIPT_NAME')toos.environ.get('URL_PREFIX')with detailed comments explaining the changeSCRIPT_NAME=/localcatoURL_PREFIX=/localcaMigration Guide
Users deploying with Traefik should update their
docker-compose-traefik.yml:Then restart the container. No other changes are required.
Testing
Backward Compatibility
This change is fully backward compatible for:
docker-compose-traefik.ymlThe only users affected are those already using
docker-compose-traefik.ymlwith Traefik, who will need to update their configuration file as shown above.Fixes #[issue_number]
Original prompt
Fixes #51
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.