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 ?

3
  • I found that the issue is linked with the (.*) and the $1, this replace %20 to whitespace with just a proxy_pass 127.0.0.1; this is working
    – TomPAP
    Jan 12, 2012 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. Jan 12, 2012 at 17:04
  • In my case, I had error 505 (Unrecognized HTTP version: ' HTTP/1.0') from .Net Core. The solution below fixed it. Sep 24, 2019 at 13:24

1 Answer 1

36

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).

1
  • Thanks, this save my day. I wonder if nginx doc mentioned this.
    – Pham
    Jul 26, 2021 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.