-
Notifications
You must be signed in to change notification settings - Fork 477
Open
Description
So I used this to build a dockerized API with Django Rest Framework. Since I develop several projects at once, I use a different port for local development. Turns out that Django or at least Django Rest Framework was not able to produce the right absolute URLs in the browsable API. Instead of localhost:12345/api, I only got localhost/api.
What I tried:
- setting
USE_X_FORWARDED_FOR_HOSTandUSE_X_FORWARDED_FOR_PORTto True, see https://docs.djangoproject.com/en/3.0/ref/settings/#use-x-forwarded-host
Anyway, what fixed it for me was using $http_host instead of $host in the nginx config.
server {
listen 80;
# server_name localhost;
charset utf-8;
location /static {
alias /usr/share/nginx/static;
}
location / {
proxy_pass http://web:8000;
proxy_set_header Host $http_host; # $host is without port, $http_host works
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
My issue: lorey/socials-api#4
My configuration: https://github.com/lorey/socials-api/tree/d7f0bca4df5be9c662ede96aac6ae89d17890404
Hope this helps anyone. Let me know if someone finds a better solution or can explain this.
Metadata
Metadata
Assignees
Labels
No labels