0

this question does not duplicate of this link

My application is web based and developed in django, deployed through UWSGI application server with nginx as a reverse proxy. The task is to redirect from https to http for a specific URL, but this sound does not simpler to me as I tried to cope up with following nginx configuration are as:

The default proxy config are as:

proxy_redirect      off;
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-Host    $host;
proxy_set_header    X-Forwarded-Server  $host;
proxy_set_header    X-Forwarded-Proto   $scheme;

The location block where Issue happened are as:

    location ~ /target\.xml$ {
        if ($scheme = https) {
           return 302 http://$host$request_uri;
        }
    }

The url which we need to redirect are as:

**https://test-server.com/api/stage/7uibsiub3jbh3v3h/target.xml**

Here if a url contains target.xml and is on https scheme then it should be redirect to http but we were receiving redirect loop in block due to missing if condition in location. As soon as we added if condition to check the scheme the nginx gave us 404 Not Found error. I had double cross check with nginx documentation which told me to not go for if condition as it could be evil most of the times so I stick with location but I am unable to debug it more.

Thanks in advance.

Shashank
  • 141
  • 1
  • 8
  • That location block processes both the `http` and `https` request for `target.xml`. The `https` request is redirected to `http`. But how is the `http` request processed? Is it a file or should it be sent to a `proxy_pass`? The `location` does not contain anything to process the `http` version of the request. – Richard Smith Jun 19 '19 at 10:47
  • The root location of api is `location ~ ^/(admin|api/) { client_max_body_size 200M; uwsgi_pass django; include uwsgi_params; }`. Where it'll be redirected to and handled by uwsgi application server through django upstream. So this location will invoke whenever a url contains api arrives. – Shashank Jun 19 '19 at 11:08
  • The preferred solution would be to split the `server` block into two `server` blocks, one for `http` and one for `https`. But an interim solution would be to add the `uwsgi` statements to your new `location` block. – Richard Smith Jun 19 '19 at 12:04
  • The server is on aws elastic load balancer and configured SSL from Interface. So we cannot override it through block, I gave a try but that does not work. Regarding the interim solution still we have to pass the http scheme with uwsgi, I am figuring out it – Shashank Jun 19 '19 at 12:24

0 Answers0