nginx strips port from 307 redirect Location header on no-trailing-slash requests #107

Closed
opened 2026-04-18 09:14:30 -07:00 by pyr0ball · 0 comments
Owner

Summary

nginx forwards Host without port, so FastAPI 307 redirects resolve to port 80.

Steps to reproduce

curl -D - http://localhost:8515/api/v1/receipts
Location: http://localhost/api/v1/receipts/ (port 8515 missing)

Expected

Location: http://localhost:8515/api/v1/receipts/

Root cause

nginx.cloud.conf uses proxy_set_header Host $host which omits the port.

Affected paths

GET /api/v1/receipts, GET /api/v1/meal-plans, GET /api/v1/health

Impact

Low for production (frontend uses trailing slashes; Caddy is HTTPS). Affects direct API consumers and dev tooling.

Fix

Change to proxy_set_header Host $http_host in nginx.cloud.conf. $http_host includes the port when present in the client request.

## Summary nginx forwards Host without port, so FastAPI 307 redirects resolve to port 80. ## Steps to reproduce curl -D - http://localhost:8515/api/v1/receipts Location: http://localhost/api/v1/receipts/ (port 8515 missing) ## Expected Location: http://localhost:8515/api/v1/receipts/ ## Root cause nginx.cloud.conf uses proxy_set_header Host $host which omits the port. ## Affected paths GET /api/v1/receipts, GET /api/v1/meal-plans, GET /api/v1/health ## Impact Low for production (frontend uses trailing slashes; Caddy is HTTPS). Affects direct API consumers and dev tooling. ## Fix Change to proxy_set_header Host $http_host in nginx.cloud.conf. $http_host includes the port when present in the client request.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Circuit-Forge/kiwi#107
No description provided.