原网页地址:
How To Limit Rate of Connections (Requests) in NGINX (tecmint.com)
The following configuration example shows limiting the rate of request to a web application API. The shared memory size is 20 MB and the request rate limit is 10 requests per second.
upstream api_service { server 127.0.0.1:9051; server 10.1.1.77:9052; } limit_req_zone $binary_remote_addr zone=limitreqsbyaddr:20m rate=10r/s; limit_req_status 429; server { listen 80; server_name testapp.tecmint.com; root /var/www/html/testapp.tecmint.com/build; index index.html; #include snippets/error_pages.conf; proxy_read_timeout 600; proxy_connect_timeout 600; proxy_send_timeout 600; location / { try_files $uri $uri/ /index.html =404 =403 =500; } location /api { limit_req zone=limitreqsbyaddr; proxy_pass http://api_service; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } }还有一篇中文文章,地址:
使用 Nginx 限流模块 limit_req_zone 来限制单位时间内的请求数目/速度/连接数 - 玩个机吧 (wangejiba.com)
这个讲得更细。
为了避免上面中文地址打不开,保存了一份PDF。
------------正 文 已 结 束, 感 谢 您 的 阅 读 (折雨的天空)--------------------
转载请注明本文标题和链接:《nginx限制访问流量,不是黑名单机制》
发表评论