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

你可能感兴趣的文章
Nginx 反向代理解决跨域问题
查看>>
Nginx 反向代理配置去除前缀
查看>>
nginx 后端获取真实ip
查看>>
Nginx 学习总结(17)—— 8 个免费开源 Nginx 管理系统,轻松管理 Nginx 站点配置
查看>>
nginx 常用配置记录
查看>>
Nginx 我们必须知道的那些事
查看>>
Nginx 的 proxy_pass 使用简介
查看>>
Nginx 的配置文件中的 keepalive 介绍
查看>>
Nginx 负载均衡与权重配置解析
查看>>
Nginx 负载均衡详解
查看>>
nginx 配置 单页面应用的解决方案
查看>>
nginx 配置https(一)—— 自签名证书
查看>>
nginx 配置~~~本身就是一个静态资源的服务器
查看>>
Nginx 配置解析:从基础到高级应用指南
查看>>
Nginx下配置codeigniter框架方法
查看>>
nginx添加模块与https支持
查看>>
Nginx用户认证
查看>>
Nginx的Rewrite正则表达式,匹配非某单词
查看>>
Nginx的使用总结(一)
查看>>
Nginx的可视化神器nginx-gui的下载配置和使用
查看>>