博客
关于我
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/

你可能感兴趣的文章
npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
查看>>
npm run build报Cannot find module错误的解决方法
查看>>
npm run build部署到云服务器中的Nginx(图文配置)
查看>>
npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
查看>>
npm scripts 使用指南
查看>>
npm should be run outside of the node repl, in your normal shell
查看>>
npm start运行了什么
查看>>
npm WARN deprecated core-js@2.6.12 core-js@<3.3 is no longer maintained and not recommended for usa
查看>>
npm 下载依赖慢的解决方案(亲测有效)
查看>>
npm 安装依赖过程中报错:Error: Can‘t find Python executable “python“, you can set the PYTHON env variable
查看>>
npm.taobao.org 淘宝 npm 镜像证书过期?这样解决!
查看>>
npm—小记
查看>>
npm介绍以及常用命令
查看>>
NPM使用前设置和升级
查看>>
npm入门,这篇就够了
查看>>
npm切换到淘宝源
查看>>
npm切换源淘宝源的两种方法
查看>>
npm前端包管理工具简介---npm工作笔记001
查看>>
npm升级以及使用淘宝npm镜像
查看>>
npm发布包--所遇到的问题
查看>>