5

I would like DRF to use for serialized hyperlinks:

http://<mydomain.com>/api/v1/endpoint

rather than

http://127.0.0.1/api/v1/endpoint

Can this be configured within Django or is it related to my http server configuration (gunicorn+nginx)?

4
  • You shouldn't have this problem once you host your app. Django will automatically configure your urls according to the domain it is hosted on. Commented Feb 17, 2015 at 8:19
  • I believe I am hosting the app already. I purchased a domain and am routing traffic to my webserver. The guides that I have read on nginx+gunicorn all favor binding gunicorn to 127.0.0.1/localhost and then proxying requests from nginx to there. Binding gunicorn to a domain name causes an error. Commented Feb 17, 2015 at 17:43
  • So this has nothing to do with DRF or Django. This is to do with your server settings. Commented Feb 18, 2015 at 7:18
  • @ZachWild, what exact settings must be changed on server? Commented May 4, 2016 at 11:20

2 Answers 2

5

Just set host header for django.

Example for nginx:

location /api/ { 
    proxy_set_header Host      $host; 
    proxy_pass http://127.0.0.1:8000;
}
Sign up to request clarification or add additional context in comments.

Comments

1

if you are using https, also add :

proxy_set_header X-Forwarded-Proto https;

and everything works fine :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.