前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >nginx 访问频率限制配置

nginx 访问频率限制配置

作者头像
py3study
发布2020-12-16 18:21:09
2.8K0
发布2020-12-16 18:21:09
举报
文章被收录于专栏:python3python3

一、概述

?由于业务需求,需要显示某个api接口,限制1分钟访问1次。

二、nginx配置

先来安装一个nginx

代码语言:javascript
复制
yum?install?-y?nginx

修改文件/etc/nginx/nginx.conf

增加红色部分

代码语言:javascript
复制
...
http?{
????#同一个请求同一个imei?一分钟限制请求1次
????limit_req_zone?$remote_addr*$arg_imei?zone=zone_imei:10m?rate=1r/m;

????log_format??main??'$remote_addr?-?$remote_user?[$time_local]?"$request"?'
??????????????????????'$status?$body_bytes_sent?"$http_referer"?'
??????????????????????'"$http_user_agent"?"$http_x_forwarded_for"';

...

????server?{
????????listen???????80?default_server;
????????listen???????[::]:80?default_server;
????????server_name??_;
????????root?????????/usr/share/nginx/html;

????????#?Load?configuration?files?for?the?default?server?block.
????????include?/etc/nginx/default.d/*.conf;

????????location?/?{
????????????limit_req?zone=zone_imei?burst=1;
????????}
...

启动nginx

代码语言:javascript
复制
nginx

访问默认页面,正常的

1.png
1.png

再刷新一次,提示错误

1.png
1.png

本文参考链接:

https://blog.csdn.net/weixin_34416754/article/details/92691038

本文参与?腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-12-14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、概述
  • 二、nginx配置
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com