8

Is there a way to proxy pass based on query parameters? I need to proxy pass root url request to server A. But, if root url has certain query parameters i need to proxy pass to server B. How can i achieve this? Below is my current configuration:

    location / {
        proxy_pass  http://xxxxxx;
        proxy_redirect     off;
        proxy_set_header   Host             $host:$server_port;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        client_max_body_size 10m;
    }
abc
  • 83
  • 1
  • 3

1 Answers1

5

You could use if statements and intermediate variables, since proxy_pass itself cannot be inside of an if statement.

location / {
    set $pp_d example.net;
    if ($arg_tld = com) {
        set $pp_d example.com;
    }
    proxy_pass http://$pp_d;
    proxy_redirect off;
    ...
}
cnst
  • 13,848
  • 9
  • 54
  • 76