Skip to content

Absolute URLs without port #66

Open
@lorey

Description

@lorey

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:

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions