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

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

目录


*Nginx与Tomcat配置

属性

Nginx

Tomcat

版本

1.14.2

Tomcat7

主机

192.168.1.XXX

192.168.1.XXX

端口

18080

8080

项目名称

xht

xht

 

Nginx初始化限流20MB

模板一

 

http{

#限流20MB

#limit_conn_zone $binary_remote_addr zone=one:20m;

 

    #限流20MB,每秒允许处理1000个请求

limit_req_zone $binary_remote_addr zone=perip:20m rate=1000r/s;

server {

location /xht {

root html;

index index.html index.htm;

limit_req zone=perip;

proxy_pass http://192.168.1.111:8080/xht;

}

}

 

}

模板二

http {

    # 总限流20MB 1000次/秒

limit_req_zone $binary_remote_addr zone=totalLimit:20m rate=1000r/s;

# 设置5MB用于图片上传,限制连接个数

limit_conn_zone $binary_remote_addr zone=uploadLimit:5m;

server {

location /xht {

root html;

index index.html index.htm;

#总流量限制和突发限制

limit_req zone=totalLimit burst=1000 nodelay;

proxy_pass http://192.168.1.111:8080/xht;

}

# 附件上传

location /uploadAttach.do{

    # 限制每个IP只允许1个并发连接

    limit_conn uploadLimit 1;

    # 每个连接上传流量限制

limit_rate  1024k;

}

}

}

模板三

http {

    # 总限流20MB 1000次/秒

limit_req_zone $binary_remote_addr zone=totalLimit:20m rate=1000r/s;

# 设置5MB用于图片上传,限制连接个数

limit_conn_zone $binary_remote_addr zone=uploadLimit:5m;

# 设置10MB用于高频接口,每秒请求频率

limit_req_zone $binary_remote_addr zone=feqLimit:10m rate=100r/s;

server {

location /xht {

root html;

index index.html index.htm;

#总流量限制和突发限制

limit_req zone=totalLimit burst=1000 nodelay;

proxy_pass http://192.168.1.111:8080/xht;

}

# 附件上传

location /uploadAttach.do{

    # 限制每个IP只允许1个并发连接

    limit_conn uploadLimit 1;

    # 每个连接上传流量限制

limit_rate  512k;

}

 

# 登录

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;

}

 

}

}

 

*Nginx文件上传设置

5MB

http {

# 设置5MB用于图片上传,限制连接个数

limit_conn_zone $binary_remote_addr zone=uploadLimit:5m;

server {

location /xht {

root html;

index index.html index.htm;

proxy_pass http://192.168.1.111:8080/xht;

}

location /uploadAttach.do {

    # 限制每个IP只允许1个并发连接

    limit_conn uploadLimit 1;

    # 每个连接上传流量限制

limit_rate  512k;

}

}

}

 

 

10MB

http {

# 设置10MB用于图片上传,限制连接个数

limit_conn_zone $binary_remote_addr zone=uploadLimit:10m;

server {

location /xht {

root html;

index index.html index.htm;

proxy_pass http://192.168.1.111:8080/xht;

}

location /uploadAttach.do {

    # 限制每个IP只允许1个并发连接

    limit_conn uploadLimit 1;

    # 每个连接上传流量限制

limit_rate  512k;

}

}

}

 

15MB

http {

# 设置15MB用于图片上传,限制连接个数

limit_conn_zone $binary_remote_addr zone=uploadLimit:15m;

server {

location /xht {

root html;

index index.html index.htm;

proxy_pass http://192.168.1.111:8080/xht;

}

location /uploadAttach.do {

    # 限制每个IP只允许1个并发连接

    limit_conn uploadLimit 1;

    # 每个连接上传流量限制

limit_rate  512k;

}

}

}

 

18MB

http {

# 设置18MB用于图片上传,限制连接个数

limit_conn_zone $binary_remote_addr zone=uploadLimit:18m;

server {

location /xht {

root html;

index index.html index.htm;

proxy_pass http://192.168.1.111:8080/xht;

}

location /uploadAttach.do {

    # 限制每个IP只允许1个并发连接

    limit_conn uploadLimit 1;

    # 每个连接上传流量限制

limit_rate  512k;

}

}

}

 

*Nginx高频接口配置[登录、实时位置、通知公告]

50r/s

http {

limit_req_zone $binary_remote_addr zone=feqLimit:20m rate=50r/s;

server {

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;

}

 

}

}

100r/s

http {

limit_req_zone $binary_remote_addr zone=feqLimit:20m rate=100r/s;

server {

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;

}

 

}

}

 

150r/s

http {

limit_req_zone $binary_remote_addr zone=feqLimit:20m rate=150r/s;

server {

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;

}

 

}

}

 

200r/s

http{

limit_req_zone $binary_remote_addr zone=feqLimit:20m rate=200r/s;

server {

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;

}

 

}

 

}

参考资料

网文参考

 

 

 

 

 

Nginx官文

 

 

 

 

限连:客户端连接限速

参考:

 

http {

#容器共使用10M的来对于IP传输开销 

  limit_conn_zone $binary_remote_addr zone=one:10m; 

server {

    location /download/ {

      limit_conn   one  1;  #限制每个IP只能发起一个并发连接

      limit_rate 300k;   #对每个连接限速300k。   

}

  }

}

#注意,这里是对连接限速,而不是对IP限速。

#如果一个IP允许两个并发连接,那么这个IP就是限速limit_rate×2。

 

限流:客户端请求的处理速率

 

http {

    limit_req_zone $ binary_remote_addr zone = one:10m rate = 1r/s;

    server{

        location /upload/{

            limit_req zone= one burst = 5;

     }

}

 

 

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

你可能感兴趣的文章
mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>