Home >Backend Development >PHP Tutorial >Simple nginx load balance example
More: http://www.webyang.net/Html/web/article_137.html
nginx is configured to run in the form of a reverse proxy, and the actual processing of the request needs to be forwarded to the back-end server for execution. There may be one or more backend servers. How to choose a suitable backend server to handle the current request is nginx load balancing.
nginx can not only be used as a powerful web server, but also as a reverse proxy server, and nginx can also realize the separation of dynamic and static pages according to scheduling rules, such as polling, IP hashing, URL hashing, weight, etc. There are many ways to load balance back-end servers.
If there is only one server and the server hangs up, it will be a disaster for the website. Therefore, load balancing will come into play at this time, and it will automatically eliminate failed servers.
The load balancing module Load-balance is an auxiliary module, which mainly serves the Upstream module. It has a clear and single goal: how to select a suitable server from multiple back-end servers for processing.
Simple example:<ol> <li value="1"> <span>http </span><span>{</span> </li> <li> <span> upstream myproject </span><span>{</span> </li> <li> <span> server </span><span>127.0</span><span>.</span><span>0.1</span><span>:</span><span>8000</span><span> weight</span><span>=</span><span>3</span><span>;</span> </li> <li> <span> server </span><span>127.0</span><span>.</span><span>0.1</span><span>:</span><span>8001</span><span>;</span> </li> <li> <span> server </span><span>127.0</span><span>.</span><span>0.1</span><span>:</span><span>8002</span><span>;</span><span></span> </li> <li> <span> server </span><span>127.0</span><span>.</span><span>0.1</span><span>:</span><span>8003</span><span>;</span> </li> <li> <span></span><span>}</span> </li> <li><span></span></li> <li> <span> server </span><span>{</span> </li> <li> <span> listen </span><span>80</span><span>;</span> </li> <li> <span> server_name www</span><span>.</span><span>domain</span><span>.</span><span>com</span><span>;</span> </li> <li> <span> location </span><span>/</span><span></span><span>{</span> </li> <li> <span> proxy_pass http</span><span>:</span><span>//myproject;</span> </li> <li> <span></span><span>}</span> </li> <li> <span></span><span>}</span> </li> <li><span>}</span></li> </ol>and other configurations can be done as usual.
Today is the fifth day of the Lunar New Year, I wish everyone a Happy New Year! Also: Let’s learn together and make progress together~
The above introduces a simple nginx load balance example, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.