In Nginx, there are some advanced scenarios where you need to dynamically forward to an unreachable upstream based on the path parameter in the URL. Scenario 1 /svr1/xxxx?yyy forwards to svr1:8080/xxxx?yyy /svr2/xxxx?yyy forwards to svr2:8080/xxxx?yyy The configuration is as follows: location ~* /(srv[1-9]+)/(.*)$ { allow all; proxy_pass http://$1/$2$is_args$args; proxy_set_header Host $host; proxy_set_header x-forwarded-for $forwarded_addr; } upstream srv1 { server srv1-ip:8080; } upstream srv2 { server srv2-ip:8080; } Scenario 2 There are 3 peer services srv1, 2, and 3 under svc1. /svc1/xxxx?yyy is forwarded to srv1/2/3:8080/xxxx?yyy There are 3 peer services srv4, 5, and 6 under svc2. /svc2/xxxx?yyy is forwarded to svr4/5/6:8080/xxxx?yyy location ~* /(svc[1-9]+)/(.*)$ { allow all; proxy_pass http://$1/$1/$2$is_args$args; proxy_set_header Host $host; proxy_set_header x-forwarded-for $forwarded_addr; } upstream svc1 { server srv1:8080; server srv2:8080; server srv3:8080; } upstream svc2 { server srv3:8080; server srv4:8080; server srv5:8080; } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: WeChat applet calculator example
>>: Standard summary for analyzing the performance of a SQL statement
Table of contents 1. What is deconstruction? 2. A...
Disclaimer: This password reset method can direct...
Linux task management - background running and te...
Preface When I was browsing Xianyu today, I notic...
After the container is started Log in to admin fi...
1. Nested routing is also called sub-routing. In ...
When we make a gradient background color, we will...
Table of contents Install tinymce, tinymce ts, ti...
Find information Some methods found on the Intern...
1. Create a new configuration file docker_nginx.c...
<br />Original article: http://www.alistapar...
Table of contents 1. Commonly used string functio...
When doing a project, it is inevitable to encount...
NodeJS copies the files: Generally, the copy oper...
background If the catalina.out log file generated...