Nginx makes a directed routing policy through the requested URL

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.