Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set current limit by nginx

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about nginx how to do current limit setting, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Let's take a look at it.

Guide: when the access pressure on the server is too high, the downgrade is realized and the unacceptable requests are redirected to the emergency interface.

1. Current-limiting nginx setting

Nginx current limiting use module upstream

Placed in the http module

# current limit concurrency

Upstream node {server 127.0.0.1:8080 max_conns=1;}

# if the request exceeds, 502 status code will be returned

Placed in the server module

# Test address. The py path of the access server will be forwarded to port 8080 of this machine.

Location / py {proxy_pass http://node/;}

# error redirect to degraded interface

Error_page 502 503 https://fund/b.html;

Note: if one is missing, the request will be forwarded to the / py path of 8080.

Proxy_pass http://node

Prepare the test environment

Open port 8080 and use web.py to open a simple port

Install web.py

Pip install web.py==0.40-dev1

Write website script webtest.py

Import weburls = ('/', 'index') class index: def GET (self): return "Hello, world!" if _ _ name__ = = "_ _ main__": app = web.application (urls, globals () app.run ()

Run script startup port python webtest.py 0.0.0.0 8080 launch port 8080 to allow any IP access

Third, test the current limit configuration

Testing with jmeter

1. Set the current limit to the number of concurrent connections 1

Request

Result

Concurrent requests 5, sent 100 times, a total of 500 requests, successful 367, failed 133

Concurrent request 10. 1000 requests were sent, with 566 successes and 434 failures

Concurrent request 20. A total of 2000 requests were sent, with success 848 and failure 1152

The above is how nginx does the current limit setting, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report