Domain name resolution in Django-rest-framework HyperlinkedModelSerializer

I would like DRF to use for serialized hyperlinks:

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

but not

http://127.0.0.1/api/v1/endpoint

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

+4
source share
2 answers

Just set the host header for django.

Example for nginx:

location /api/ { 
    proxy_set_header Host      $host; 
    proxy_pass http://127.0.0.1:8000;
}
+3
source

if you use https also add:

proxy_set_header X-Forwarded-Proto https;

and everything works fine :)

0
source

All Articles