Nginx location - Distinguish requests by arguments or queries

stmx38 nginx-forum at
Tue Feb 25 12:05:05 UTC 2020


We have a case when we should permit different methods on the same location
but different requests.

For location /test we should permit only POST, for /test?doc we should
permit only GET methods.

Our config example:
  location /test {
    error_page  403 =405 /custom-error;

    limit_except POST {
      deny all;

    proxy_pass http://test/in;

Map doesn't help us, it can't be used inside 'limit_except'. We also tried
to use 'if' to pass a request to named location using 'try_files' but it
also is not allowed inside 'if'.

Can't be used:
limit_except $method {
  deny all;

if ($request_uri ~ \?doc) {
  try_files @test-doc;

The question is, if there a way to implement this and how?

Thank you!

Posted at Nginx Forum:,287101,287101#msg-287101

More information about the nginx mailing list