博客
关于我
Nginx配置限流限连接示例及相关知识汇总
阅读量:172 次
发布时间:2019-02-28

本文共 3565 字,大约阅读时间需要 11 分钟。

Nginx与Tomcat配置及限流设置指南

一、Nginx与Tomcat的配置

Nginx与Tomcat的配置主要用于前端反向代理和负载均衡,以下是常见的配置示例:

1.1 项目部署

http {    server {        location /xht {            root html;            index index.html index.htm;            proxy_pass http://192.168.1.111:8080/xht;        }    }}

1.2 限流设置

# 限流20MB,允许1000次/秒limit_req_zone $binary_remote_addr zone=perip:20m rate=1000r/s;# 总限流20MB,允许1000次/秒limit_req_zone $binary_remote_addr zone=totalLimit:20m rate=1000r/s;# 附件上传设置location /uploadAttach.do {    limit_conn uploadLimit 1;    limit_rate 512k;}

二、文件上传设置

不同大小的上传设置,适用于不同的场景:

2.1 5MB

limit_conn_zone $binary_remote_addr zone=uploadLimit:5m;location /xht {    root html;    index index.html index.htm;    proxy_pass http://192.168.1.111:8080/xht;}location /uploadAttach.do {    limit_conn uploadLimit 1;    limit_rate 512k;}

2.2 10MB

limit_conn_zone $binary_remote_addr zone=uploadLimit:10m;location /xht {    root html;    index index.html index.htm;    proxy_pass http://192.168.1.111:8080/xht;}location /uploadAttach.do {    limit_conn uploadLimit 1;    limit_rate 512k;}

2.3 15MB

limit_conn_zone $binary_remote_addr zone=uploadLimit:15m;location /xht {    root html;    index index.html index.htm;    proxy_pass http://192.168.1.111:8080/xht;}location /uploadAttach.do {    limit_conn uploadLimit 1;    limit_rate 512k;}

2.4 18MB

limit_conn_zone $binary_remote_addr zone=uploadLimit:18m;location /xht {    root html;    index index.html index.htm;    proxy_pass http://192.168.1.111:8080/xht;}location /uploadAttach.do {    limit_conn uploadLimit 1;    limit_rate 512k;}

三、高频接口配置

3.1 50r/s

limit_req_zone $binary_remote_addr zone=feqLimit:20m rate=50r/s;location /xht {    root html;    index index.html index.htm;    proxy_pass http://192.168.1.111:8080/xht;}location /login_gis/loginVerify.do {    limit_req zone=feqLimit burst=50;}location /userLogin.do {    limit_req zone=feqLimit burst=50;}location /sendXhyPos.do {    limit_req zone=feqLimit burst=50;}location /getMessage.do {    limit_req zone=feqLimit burst=50;}

3.2 100r/s

limit_req_zone $binary_remote_addr zone=feqLimit:20m rate=100r/s;location /xht {    root html;    index index.html index.htm;    proxy_pass http://192.168.1.111:8080/xht;}location /login_gis/loginVerify.do {    limit_req zone=feqLimit burst=100;}location /userLogin.do {    limit_req zone=feqLimit burst=100;}location /sendXhyPos.do {    limit_req zone=feqLimit burst=100;}location /getMessage.do {    limit_req zone=feqLimit burst=100;}

3.3 150r/s

limit_req_zone $binary_remote_addr zone=feqLimit:20m rate=150r/s;location /xht {    root html;    index index.html index.htm;    proxy_pass http://192.168.1.111:8080/xht;}location /login_gis/loginVerify.do {    limit_req zone=feqLimit burst=150;}location /userLogin.do {    limit_req zone=feqLimit burst=150;}location /sendXhyPos.do {    limit_req zone=feqLimit burst=150;}location /getMessage.do {    limit_req zone=feqLimit burst=150;}

3.4 200r/s

limit_req_zone $binary_remote_addr zone=feqLimit:20m rate=200r/s;location /xht {    root html;    index index.html index.htm;    proxy_pass http://192.168.1.111:8080/xht;}location /login_gis/loginVerify.do {    limit_req zone=feqLimit burst=200;}location /userLogin.do {    limit_req zone=feqLimit burst=200;}location /sendXhyPos.do {    limit_req zone=feqLimit burst=200;}location /getMessage.do {    limit_req zone=feqLimit burst=200;}

四、参考资料

4.1 网文参考

  • 《Nginx官方文档》
    详细介绍了Nginx的各种配置选项和使用方法。

4.2 限连与限流设置

  • 限连:限制客户端的连接数量,避免过多的并发请求。
    示例:limit_conn uploadLimit 1;
  • 限流:限制客户端的请求速率,控制高频接口的访问流量。
    示例:limit_req_zone $binary_remote_addr zone=feqLimit:20m rate=100r/s;

转载地址:http://vexj.baihongyu.com/

你可能感兴趣的文章
Objective-C实现all subsequences所有子序列算法(附完整源码)
查看>>
Objective-C实现AlphaNumericalSort字母数字排序算法(附完整源码)
查看>>
Objective-C实现alternate disjoint set不相交集算法(附完整源码)
查看>>
Objective-C实现alternative list arrange备选列表排列算法(附完整源码)
查看>>
Objective-C实现An Armstrong number阿姆斯特朗数算法(附完整源码)
查看>>
Objective-C实现anagrams字谜算法(附完整源码)
查看>>
Objective-C实现ApproximationMonteCarlo蒙特卡洛方法计算pi值算法 (附完整源码)
查看>>
Objective-C实现area under curve曲线下面积算法(附完整源码)
查看>>
Objective-C实现arithmetic算术算法(附完整源码)
查看>>
Objective-C实现armstrong numbers阿姆斯壮数算法(附完整源码)
查看>>
Objective-C实现articulation-points(关键点)(割点)算法(附完整源码)
查看>>
Objective-C实现atoi函数功能(附完整源码)
查看>>
Objective-C实现average absolute deviation平均绝对偏差算法(附完整源码)
查看>>
Objective-C实现average mean平均数算法(附完整源码)
查看>>
Objective-C实现average median平均中位数算法(附完整源码)
查看>>
Objective-C实现average mode平均模式算法(附完整源码)
查看>>
Objective-C实现avl 树算法(附完整源码)
查看>>
Objective-C实现AvlTree树算法(附完整源码)
查看>>
Objective-C实现backtracking Jump Game回溯跳跃游戏算法(附完整源码)
查看>>
Objective-C实现BACKTRACKING 方法查找集合的幂集算法(附完整源码)
查看>>