I have sett up reverse proxy with Nginx reverse proxy is just working fine as expected. I have another scenario where i need to redirect URL based on matching string using proxy_pass.

ie : http://xx.xx.xx.xx:81/crawlers/587dbbf8e4b0b5cea2c4a49e/execute?url=https%3A%2F%2Fwww.massimodutti.com%2Fes%2Fhombre%2Faccesorios%2Fbolsas-c1748214p7722308.html%3Fkeyword%3DBANDOLERA%2520PEQUE%25C3%2591A%2520PIEL%2520BURTON%26colorId%3D700&token=5892cf1cf056fa9ac307a39c&

This is the rest call i want if URL contains massimodutti.de so it should be route to german servers using proxy_pass

currently i am blank and searching for solution any help will be highly appreciated...


You should use the nginx map feature to map query arguments into proxy_pass destinations. It works like this:

In the nginx configuration http level, you add a map like this:

map $arg_url $proxyserver {
    default default.server;
    "~\.de" german.server;

where you replace default.server with the domain name for default server and german.server with the domain name for your german server.

Then, you use proxy_pass http://$proxyserver; in your server block for the reverse proxy destination definition.


I have achieved this by adding these lines in my nginx reverse proxy configurations $args is case insensitive searching method it will search ".de" in requested URL and proxy the request.

if ( $args ~ ".de" ) { proxy_pass http://104.xx.xx.xx:80; }

if ( $args ~ ".ca" ) { proxy_pass http://104.xx.xx.xx:80; }

  • 1
    This is the wrong way to do it. Look at the answer above, and read this article nginx.com/resources/wiki/start/topics/depth/ifisevil – Tim Feb 9 '17 at 8:29
  • i have tried again didn't working for me either i can't share full logs here Here is my configuration ..... server { listen 80; location ~* massimodutti.de { proxy_pass xx.xx.xx.xx:80 } location / { #if ( $args ~ ".de" ) { #proxy_pass xx.xx.xx.xx:xx; #} – Mansur Ali Feb 9 '17 at 8:50
  • A better match can be achieved by using $arg_url instead of $args. Then nginx will match the url query argument instead of the complete argument string. The most recommended way is described in my answer. – Tero Kilkanen Feb 9 '17 at 22:24

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.