[Django]-Http POST drops port in URL

39πŸ‘

βœ…

I have the same problem with my development server.
After some internet search I’ve found this discussion (nginx, apache, and odd admin error) where the solution is to modify the proxy configuration of nginx.

The configuration setting to modify is:

proxy_set_header            Host $host;

the solution is to add the port number:

proxy_set_header            Host $host:$server_port;

In my ngnix + apache2 (with worker mpm) + django now all works well.

πŸ‘€Techside

10πŸ‘

You want to pass on the original HTTP Host header, which arrived at nginx:

proxy_set_header Host $http_host;

This appears to be a bug with the default configuration of nginx in Debian/Ubuntu, which uses only $host: $host will not contain the $server_port.
(This is configured in /etc/nginx/proxy_params for the Debian/Ubuntu package, and you might override it in your configuration after including it.)

Please note that $host:$server_port is different from $http_host.
See http://wiki.nginx.org/HttpCoreModule#.24host for an explanation.

Reported and fixed in Debian: http://bugs.debian.org/733016

πŸ‘€blueyed

6πŸ‘

Given everything you’re concerned with is clear HTTP (unlike something like AJP for instance) I’d run a protocol analyser such as Wireshark on the host and determine at which point the redirect is introduced.

πŸ‘€Danny Thomas

2πŸ‘

Check the error logs. On Linux mine are at /var/log/apache2. Just running a search for error.log should turn it up.

πŸ‘€John

0πŸ‘

If you find that this occurs with a url derived from the get_absolute_url() method of a model, you should use pass that path to HttpRequest.build_absolute_url() in order to prepend the hostname and port to the path.

Leave a comment