六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 303|回复: 0

Nginx屏蔽某ip/网段访问

[复制链接]
 楼主| 发表于 2013-9-11 23:47:45 | 显示全部楼层 |阅读模式
主要是为了防止蜘蛛采集或别人攻击,具体步骤如下:
  在nginx配置目录下,新建deny.conf文件,如下所示:
  1. [root@mail conf.d]# pwd
  2.         /etc/nginx/conf.d
  3.         [root@mail conf.d]# ll
  4.         -rw-r--r--. 1 root root   19  2月 22 15:28 deny.conf
  5.         [root@mail conf.d]# cat deny.conf
  6.         deny 123.7.84.160;
复制代码
其中:
  deny 123.7.84.160;    #屏蔽123.7.84.160
deny 123.7.84.0/24;   #屏蔽123.7.84.1 ~ 123.7.84.255整个网段IP
  再让nginx.conf加载此配置文件,如下所示(nginx1.x默认会加载/etc/nginx/conf.d/下的所有配置文件):
  1. root@mail nginx]# pwd
  2. 02        /etc/nginx
  3. 03        [root@mail nginx]# ll
  4. 04        总用量 36
  5. 05        drwxr-xr-x. 2 root root 4096  2月 22 15:28 conf.d
  6. 06        -rw-r--r--. 1 root root  964 12月 12 00:57 fastcgi_params
  7. 07        -rw-r--r--. 1 root root 2837 12月 12 00:57 koi-utf
  8. 08        -rw-r--r--. 1 root root 2223 12月 12 00:57 koi-win
  9. 09        -rw-r--r--. 1 root root 3463 12月 12 00:57 mime.types
  10. 10        -rw-r--r--. 1 root root 1052  2月  6 15:22 nginx.conf
  11. 11        -rw-r--r--. 1 root root  596 12月 12 00:57 scgi_params
  12. 12        -rw-r--r--. 1 root root  623 12月 12 00:57 uwsgi_params
  13. 13        -rw-r--r--. 1 root root 3610 12月 12 00:57 win-utf
  14. 14        [root@mail nginx]# cat nginx.conf
  15. 15        ..........(以上省略)
  16. 16        http {
  17. 17            include /etc/nginx/conf.d/*.conf;
  18. 18            ..........(以下省略)
  19. 19        }
复制代码
本文摘自:http://www.juziku.com/sunlightcs/wiki/6440.htm



该会员没有填写今日想说内容.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表