Nginx – How to match string in URL using Nginx

nginxreverse-proxyrewrite

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…

Best Answer

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.