Use Nginx’s Django REST framework absolute URL always returns 127.0.0.1

I use gunicorn/django (using django-rest-framework) behind nginx to run the application, and when using hyperlinkedmodelserializer, I have a little problem with the url return using the rest of the framework. They Always return something like http://127.0.0.1/ instead of my hostname.

Can you help?

It’s okay, I found that I forgot

proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

In my nginx configuration. It works fine now.

I use gunicorn/django (using django-rest-framework) behind nginx to run the application, and when using hyperlinkedmodelserializer, I have a little problem with the url return using the rest of the framework. They always return Similar to http://127.0.0.1/ instead of my hostname.

Can you help?

It’s okay, I found out I forgot

proxy_set_header Host $host:$server_port; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

In my nginx configuration. It works fine now.

Leave a Comment

Your email address will not be published.