Application has a scene is required according to the URL in the "&_router=10.0.0.1" parameter specified by the machine to be forwarded to the appropriate machine to do processing, looked at the Nginx document, found can be completed by the embedded variable $arg_, more convenient and flexible, the code is as follows:
Location/{if ($arg __router = 10.0.0.1) {Proxy_pass http://10.0.0.1:8080; Break } if ($arg __router = 10.0.0.2) {Proxy_pass http://10.0.0.2:8080; Break } Proxy_pass http://bakend;}
After completing the above configuration, Nginx receives the "/api/start.do?run=ok&_router=10.0.0.1" request will be forwarded to "http://10.0.0.1:8080" this machine processing, In order to achieve the URL according to the parameters of the development of directional Policy routing. Can also be based on other parameters of the URL to make a policy, such as: "/api/start.do?run=ok&_type=app"
Location/{if ($arg __type = app) {Proxy_pass http://apphost; Break } if ($arg __type = game) {Proxy_pass http://gamehost; Break } Proxy_pass http://bakend;}
After the directional routing is done, start configuring load and disaster recovery, take apphost as an example:
Upstream Apphost {server 10.1.1.1:8080; #1 server 10.1.1.2:8080; #2 server 10.1.1.3:8080 Backup; #3}
1, 2nd servers assume the daily request traffic, when the server 1 and 2nd are all unavailable, 3rd server then process the request. The role of backup is to not participate in the load normally, and only accept requests if there are no other available members in the group.
This article is from the "Camouflage Small snail" blog, please be sure to keep this source http://cycool.blog.51cto.com/2443397/1568577
Nginx makes a directed routing policy through the requested URL