Home >Operation and Maintenance >Nginx >How to set nginx current limit

How to set nginx current limit

PHPz
PHPzforward
2023-05-26 10:07:262376browse

How to set nginx current limit

1. Current-limiting nginx settings

nginx current-limiting module upstream

is placed in the http module# Current limiting concurrency

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

#Exceeding requests will return a 502 status code

Place it in the server module

#test address, and access the server py path will be forwarded to the local machine's 8080 Port

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

#Error redirect to downgrade 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;

2. 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 the website script webtest.py

import web

urls = (
   '/', 'index')

class index:
   def GET(self):
       return "Hello, world!"if __name__ == "__main__":
   app = web.application(urls, globals())
   app.run()

Run the script to start the port python webtest.py 0.0.0.0:8080. Start the 8080 port to allow any IP access

3. Test current limiting configuration

Use jmeter to test

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

Request

How to set nginx current limit

Result

How to set nginx current limit

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

Concurrent requests 10. Sent 100 times, a total of 1000 requests, 566 successful, 434 failed

Concurrent requests 20. Sent 100 times, 2000 requests in total, 848 successful, 1152 failed

The above is the detailed content of How to set nginx current limit. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete