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
background: The site is separated from the front ...
Table of contents Preface The difference between ...
Table of contents Problem Description 1. Basic so...
This article shares the specific code of JavaScri...
Recently I have used the function of renaming sto...
How to achieve internationalization in React? The...
There are many ways to write and validate form fi...
1. Problem Description When starting MYSQL, a pro...
How to center an element in the browser window He...
1. Before configuring the IP address, first use i...
First time writing. Allow me to introduce myself....
Three functions: 1. Automatic vertical centering o...
Table of contents Overall Effect Listen for conta...
Table of contents Overview Virtual Dom principle ...
What to do if you forget your Linux/Mac MySQL pas...