11

I am using a nginx as a proxy for an apache server.

Here is my config:

location ~ ^/subsite/(.*)$ {
        proxy_pass http://127.0.0.1/subsite/$1?$query_string;
    }

the problem is that if I send a request with %20 like mywebsite.com/subsite/variable/value/title/Access%20denied/another/example

the %20 is replaced by a whitespace, and apache don't care about all the end of the request after Access /title/Access

Any Idea ?

TomPAP
  • 249
  • 4
  • 12
  • I found that the issue is linked with the (.*) and the $1, this replace %20 to whitespace with just a proxy_pass http://127.0.0.1; this is working – TomPAP Jan 12 '12 at 17:00
  • 3
    As soon as you are able, you can/should answer/accept your own question so others will know that there is a solution. Welcome to Stack Overflow. – Jonathan Spooner Jan 12 '12 at 17:04
  • In my case, I had error 505 (Unrecognized HTTP version: ' HTTP/1.0') from .Net Core. The solution below fixed it. – Jonathan Rioux Sep 24 '19 at 13:24

1 Answers1

39

I was able to solve a similar issue -- we have an api that requires the search terms to be part of the URL path. Passing the output directly to the proxy_pass directive caused it to throw a 502 even though the request was properly url encoded.

Here's the solution we came up with:

location ~ /api/search(/.*) {
        set $query $1;
        proxy_pass http://127.0.0.1:3003$query;

    }

The "set" directive seems to keep the url encoding intact (or re-encodes from what the regex is passing back in $1).

steamedcotton
  • 401
  • 4
  • 5