Basically I have this nginx.conf file where I receive some parameters from my index.html page form. One of these parameters is called $url and I use it to do a:

proxy_pass $url;

The thing is that the operation fails because the $url seem to be encoded and in my error.log file I see something like this:

[error] 18849#18849: *195088 invalid URL prefix in "http%3A%2F%2Fexample.com"

However, if I hardcode the operation like this:

proxy_pass http://example.com;

or like this:

set $url_backup http://example.com
proxy_pass $url_backup;

it works without any problem.

How can I fix the URL issue ? Thanks

  • Hello, are you using GET or POST in your index.html form? This shows clearly that your form is posting your values encoded, which is normal.
    – moutonjr
    Dec 19, 2017 at 9:57
  • I use GET because I heared that nginx does not know about POST. Basically my url looks like this: my-url.com?myURL=http%3A%2F%2Fexample.com and I want to use the myUrl param. Dec 19, 2017 at 10:08
  • How did you get $url variable?
    – Alexey Ten
    Dec 19, 2017 at 12:12

1 Answer 1


Basically, as you are using GET parameters for your $url syntax, encoding of strings is compulsory for HTTP's URLs. That's why every special char is escaped from your form to your URL.

But you can get your things done by a LUA scripot with the nginx-lua-module's ngx-escape-uri by decoding your URL:

newstr = ngx.unescape_uri($url)

(depending on how you got your URL)

Sources: https://stackoverflow.com/questions/20282054/how-to-urldecode-a-request-uri-string-in-lua

  • 2
    I am intrested to do it natively without adding new modules to nginx. Dec 21, 2017 at 10:27

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.