my upstream:
upstream upstream_**uba1**_console_f485c00e45256742e2cc641db834b150 { ip_hash; server 192.30.56.172:39443; check interval=2000 rise=1 fall=3 timeout=3000; } upstream upstream_**uba2**_console_f485c00e45256742e2cc641db834b150 { ip_hash; server 192.30.56.173:39443; check interval=2000 rise=1 fall=3 timeout=3000; } my location:
location /opsuba/ { if ($args ~* region=(\w+?)(&|$)) { set $region $1; } limit_req zone=reqconsole burst=10000 nodelay; limit_conn connconsole 1000; **proxy_pass include error_page_exclude_ajax.conf; include static_file.conf; access_log off; } how can i make upstream_${region}_console_f485c00e45256742e2cc641db834b150 replace with variables?
1 Answer
You specify the variable like $1 (from regexp) or $region from the set command.
This should work in your config:
proxy_pass I've just tested it with this example config:
upstream upstream_uba1_console_f485c00e45256742e2cc641db834b150 { ip_hash; server 127.0.0.1:39443; } upstream upstream_uba2_console_f485c00e45256742e2cc641db834b150 { ip_hash; server 127.0.0.1:39444; } server { listen 80; location ~ ^/([^\/]*) { proxy_pass } } server { listen 39443; root /var/www/; location / { try_files /url1.html $uri; } } server { listen 39444; root /var/www/; location / { try_files /url2.html $uri; } } Files on the filesystem:
/var/www/url1.html -> content url 1 /var/www/url2.html -> content url 2 Access through:
-> url1.html -> url2.html I did everything with local backends but will work with yours too.
Also I had to remove some params from your upstream block to make it work.