博客
关于我
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实现cocktail shaker sort鸡尾酒排序算法(附完整源码)
查看>>
Objective-C实现cocktailShakerSort鸡尾酒排序算法(附完整源码)
查看>>
Objective-C实现CoinChange硬币兑换问题算法(附完整源码)
查看>>
Objective-C实现collatz sequence考拉兹序列算法(附完整源码)
查看>>
Objective-C实现Collatz 序列算法(附完整源码)
查看>>
Objective-C实现comb sort梳状排序算法(附完整源码)
查看>>
Objective-C实现combinationSum组合和算法(附完整源码)
查看>>
Objective-C实现combinations排列组合算法(附完整源码)
查看>>
Objective-C实现combine With Repetitions结合重复算法(附完整源码)
查看>>
Objective-C实现combine Without Repetitions不重复地结合算法(附完整源码)
查看>>
Objective-C实现conjugate gradient共轭梯度算法(附完整源码)
查看>>
Objective-C实现connected components连通分量算法(附完整源码)
查看>>
Objective-C实现Connected Components连通分量算法(附完整源码)
查看>>
Objective-C实现Convex hull凸包问题算法(附完整源码)
查看>>
Objective-C实现convolution neural network卷积神经网络算法(附完整源码)
查看>>
Objective-C实现convolve卷积算法(附完整源码)
查看>>
Objective-C实现coulombs law库仑定律算法(附完整源码)
查看>>
Objective-C实现counting sort计数排序算法(附完整源码)
查看>>
Objective-C实现countSetBits设置位的数量算法(附完整源码)
查看>>
Objective-C实现currency converter货币换算算法(附完整源码)
查看>>