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

How to set nginx current limit

PHPz
Release: 2023-05-26 10:07:26
forward
2379 people have browsed it

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;
}
Copy after login

#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/;
}
Copy after login

#Error redirect to downgrade interface

error_page 502 503 https://fund/b.html;
Copy after login

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

proxy_pass http://node;
Copy after login

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
Copy after login

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()
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template