Nginx如何配置除某个IP之外,其他IP,同一IP访问频率限制为30次/每秒

一、限制所有单个ip的访问频率

1、http中的配置

http {

    #$limit_conn_zone:限制并发连接数
    limit_conn_zone $binary_remote_addr zone=one1:10m;

    #limit_req_zone:请求频率
    #$binary_remote_addr:以客户端IP进行限制
    #zone=one:10m:创建IP存储区大小为10M,用来存储访问频率
    #rate=10r/s:表示客户端的访问评率为每秒10次
    limit_req_zone $binary_remote_addr zone=one2:10m   rate=30r/s;

}

2、server配置

server {
        listen       80;
        server_name  localhost;

        location / {
            #限制并发数2
            limit_conn  one1  2;
            #burst:如果请求的频率超过了限制域配置的值,请求处理会被延迟
            #nodelay:超过频率限制的请求会被延迟,直到被延迟的请求数超过了定义的阈值,这个请求会被终止,并返回503
            limit_req   zone=one2 burst=10 nodelay;
            root   html;
            index  index.html index.htm;
        }

}

  

3、访问白名单设置

http {
# geo:指令定义了一个白名单$limited变量,默认值为1,如果客户端ip在上面的范围内,$limited的值为0
    geo $limited{
        default 1;
        10.0.0.140 0;  #把10.0.0.140设置为白名单
        10.0.0.141 0;  #白名单ip,可继续添加
    }
    #使用map指令映射搜索引擎客户端的ip为空串,如果不是搜索引擎就显示本身真是的ip
    #这样搜索引擎ip就不能存到limit_req_zone内存session中,所以不会限制搜索引擎的ip访问

    map $limited $limit {
$binary_remote_addr;
"";
    }
    limit_conn_zone $limit zone=one:20m;
    limit_req_zone $limit zone=one2:20m   rate=30r/s;
}

  

原文地址:https://www.cnblogs.com/Mr-Echo/p/12229908.html

时间: 2024-08-02 04:01:38

Nginx如何配置除某个IP之外,其他IP,同一IP访问频率限制为30次/每秒的相关文章

在nginx中配置如何防止直接用ip访问服务器web server及server_name特性讲解

看了很多nginx的配置,好像都忽略了ip直接访问web的问题,不利于SEO优化,所以我们希望可以避免直接用IP访问网站,而是域名访问,具体怎么做呢,看下面. 官方文档中提供的方法: If you do not want to process requests with undefined “Host” header lines, you may define a default server that just drops the requests: server { listen 80 de

Nginx的配置文件简介及在Nginx中配置基于不同ip的虚拟主机

Nginx的配置文件简介及在Nginx中配置基于不同ip的虚拟主机: #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; defa

【Linux】添加Nginx代理配置只允许内部IP访问

location / { index index.jsp; proxy_next_upstream http_500 http_502 http_503 http_504 error timeout invalid_header; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; deny 192.168.1.1;

Nginx安装配置详解

1.   Nginx安装 1)下载Nginx: wget http://nginx.org/download/nginx-1.3.11.tar.gz /opt/ 2)安装Nginx: ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-md5=/usr/lib

nginx全局配置和性能优化

nginx目录结构和命令 1.ls /apps/nginx/:         html是测试页,sbin是主程序 2.ls /apps/nginx/sbin/:  nginx 只有一个程序文件 3.ls /apps/nginx/html/:  50x.html index.html 测试网页 ?nginx:默认为启动nginx -h 查看帮助选项 -V 查看版本和配置选项 -t 测试nginx语法错误 -c filename 指定配置文件(default: /etc/nginx/nginx.c

Nginx 核心配置详解

目录 Nginx 核心配置详解 Nginx 四层访问控制: Nginx账户认证功能: 自定义错误页面: 自定义访问日志: 检测文件是否存在: 长连接配置: 作为下载服务器配置: 作为上传服务器: 其他配置: Nginx 核心配置详解 Nginx 四层访问控制: 准备两个客户端,做访问测试使用. centos7 IP:192.168.39.7 centos6 IP:192.168.39.6 [[email protected] images1]#vim /apps/nginx/conf/conf.

linux下Nginx配置文件(nginx.conf)配置设置详解(windows用phpstudy集成)

linux备份nginx.conf文件举例: cp /usr/local/nginx/nginx.conf /usr/local/nginx/nginx.conf-20171111(日期) 在进程列表里 面找master进程,它的编号就是主进程号. ps -ef | grep nginx 查看进程 cat /usr/local/nginx/nginx.pid 每次修改完nginx文件都要重新加载配置文件linux命令: /usr/local/nginx -t //验证配置文件是否合法 若ngin

FastDFS的php和nginx模块配置

一.FastDFS和php整合 1.安装php # 安装依赖包 yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel cu

Nginx安装配置(转)

Nginx 安装配置 Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器. 在高连接并发的情况下,Nginx是Apache服务器不错的替代品. Nginx 安装 系统平台:CentOS release 6.6 (Final) 64位. 一.安装编译工具及库文件 yum -y install make zlib zlib-devel gcc-c++ libtoo