#31354: When I am using a reverse proxy on a non-standard port 
request.get_host()
does not include the port
-------------------------------------+-------------------------------------
               Reporter:  dgcgh      |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:             |        Version:  3.0
  Uncategorized                      |       Keywords:  request get_host
               Severity:  Normal     |  build_absolute_uri
           Triage Stage:             |      Has patch:  1
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  1
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 request.get_port() should include the port of the authority if it is not
 80 for http or 443 for https. Currently this does not happen when
 HTTP_X_FORWARDED_HOST is present in request.META.

 This causes issues for e.g. request.build_absolute_uri() if the django app
 is running behind a reverse proxy on a non-standard port.

 Example would be: nginx is listening on port 8443 and forwarding to a
 django server listening on port 8001:
 {{{
 server {
     listen      8443 ssl;
     server_name         localhost.example.com

    location / {
         proxy_pass  http://localhost:8001;
         # include     /etc/nginx/uwsgi_params;
         proxy_cache_bypass  $http_upgrade;

         proxy_set_header Upgrade           $http_upgrade;
         proxy_set_header Connection        "upgrade";
         proxy_set_header Host              $host;
         proxy_set_header X-Real-IP         $remote_addr;
         proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
         proxy_set_header X-Forwarded-Proto $scheme;
         proxy_set_header X-Forwarded-Host  $host;
         proxy_set_header X-Forwarded-Port  $server_port;
     }
 }
 }}}

 In this case URIs built with request.build_absolute_uri() in a django app
 will exclude the port, i.e.:
 {{{request.build_django_uri("/") == "https://localhost.example.com/"}}}
 where it should return "https://localhost.example.com:8443/";

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31354>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/048.406ce845cecb43ba8e44e8faeb431664%40djangoproject.com.

Reply via email to