I am quite new to nginx so excuse me in advance if I am asking something obvious.

What I am trying to do is to proxypass to another server a request that comes to my nginx server in the form of:


The way tried to do this was:

  location ~* ^/locationA/results\?(.*)test=true$ {
deny all ;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass   http://myserver.org/ ;
proxy_redirect off;

The above example doesn't work and with a bit of Googling I found out that you cannot use regex on location with proxy_pass.

Is there any other way to achieve this?


I have figured out how to achieve this by doing the following:

 location / {

 if ($arg_test ~ "true") {
    set $gotoserver 1;
if ($uri ~* "(queries|results)") {
   set $gotoserver  "${gotoserver}1" ;
if ($gotoserver = 11) {
proxy_pass http://myserver.org ;
| improve this answer | |

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.