Can nginx location
blocks match a URL query string?
For example, what location block might match HTTP GET
request
GET /git/sample-repository/info/refs?service=git-receive-pack HTTP/1.1
Can nginx location
blocks match a URL query string?
For example, what location block might match HTTP GET
request
GET /git/sample-repository/info/refs?service=git-receive-pack HTTP/1.1
Short answer: No.
Long answer: There is a workaround if we have only a handful of such location blocks.
Here's a sample workaround for 3 location blocks that need to match specific query strings:
You may use $query_string, $args or $arg_fieldname. All will do the job. You may know more about error_page in the official docs.
Warning: Please be sure not to use the standard HTTP codes.
I know this question is over a year old, but I've spent the last few days destroying my brain over a similar problem. I wanted different authentication and handling rules for public and private repos, including pushing and pulling. This is what I finally came up with, so I figured I'd share. I know
if
is a tricky directive, but this seems to work for me just fine:There is another way this can be done, if you are using nginx as a proxy.
set a variable in the server block:
Inside the location block, add the if:
And add two new proxy directives:
it will always forward to the upstream server with no cache