11

Nginx is serving only static files, yet, some of file names contains '?'. Yes, the question mark.

All URLs that contains '?' yield 404 even though file actually exists. e.g.

> GET /foo?lang=ar.html HTTP/1.1
...
...
< HTTP/1.1 404 Not Found

While a file named foo?lang=ar.html does exists in the expected location.

I wonder if there is a way to tell Nginx to treat the entire request as URL including what is currently translated as query string.

The only solution I have in mind is to write a small web server that does this and have nginx reverse proxy that web server, but I prefer get it done with nginx alone.

2
  • 2
    Well, a question mark is a special character that denotes the start of the query string, so it can never be part of the file name.. I can't test right now but maybe try replacing it in the URL with the escaped version, %3f. Oct 5, 2012 at 16:40
  • @ShaneMadden That will work, but how would you be able to differentiate between a filename and just an URI pointing to a CGI accepting parameters? Looks like this is going to be an administrative nightmare. :) Edit: It will definetly work. Just tried it on my webserver and I got an GET /header.php%3fbla HTTP/1.1" 404. Oct 5, 2012 at 17:24

1 Answer 1

14

You can use try_files with either $request_uri or $uri$is_args$args depending on whether you want to have the urlencoded bits decoded or not when looking for the filename.

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.