Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absolute URLs without port #66

Open
lorey opened this issue May 6, 2020 · 0 comments
Open

Absolute URLs without port #66

lorey opened this issue May 6, 2020 · 0 comments

Comments

@lorey
Copy link

lorey commented May 6, 2020

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.

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

No branches or pull requests

1 participant