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

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

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/

你可能感兴趣的文章
Node-RED中使用json节点解析JSON数据
查看>>
Node-RED中使用node-random节点来实现随机数在折线图中显示
查看>>
Node-RED中使用node-red-browser-utils节点实现选择Windows操作系统中的文件并实现图片预览
查看>>
Node-RED中使用node-red-contrib-image-output节点实现图片预览
查看>>
Node-RED中使用node-red-node-ui-iframe节点实现内嵌iframe访问其他网站的效果
查看>>
Node-RED中使用Notification元件显示警告讯息框(温度过高提示)
查看>>
Node-RED中使用range范围节点实现从一个范围对应至另一个范围
查看>>
Node-RED中实现HTML表单提交和获取提交的内容
查看>>
Node-RED中将CSV数据写入txt文件并从文件中读取解析数据
查看>>
Node-RED中建立TCP服务端和客户端
查看>>
Node-RED中建立Websocket客户端连接
查看>>
Node-RED中解析高德地图天气api的json数据显示天气仪表盘
查看>>
Node-RED中通过node-red-ui-webcam节点实现访问摄像头并截取照片预览
查看>>
Node-RED安装图形化节点dashboard实现订阅mqtt主题并在仪表盘中显示温度
查看>>
Node-RED订阅MQTT主题并调试数据
查看>>
node-request模块
查看>>
Node.js 8 中的 util.promisify的详解
查看>>
node.js url模块
查看>>
Node.js Web 模块的各种用法和常见场景
查看>>
Node.js 函数是什么样的?
查看>>