LNMP--nginx 访问控制

2018-02-17

LNMP--nginx 访问控制

  以下语句的插入请注意对应配置位置,区分全局和局部生效。

  限制只让某个 ip 访问,加如下配置:

allow   192.168.1.101;

deny    all;

  禁止某个 IP 或者 IP 段访问站点的设置方法,首先建立下面的配置文件放在 nginx 的 conf 目录下面,命名为 deny.ip

[root@localhost ~]# vim /usr/local/nginx/conf/deny.ip

deny 192.168.1.11;

deny 192.168.1.123;

deny 10.0.1.0/24;

  在对应的虚拟主机配置文件中加入:

include deny.ip;

  重启一下 nginx 的服务:

[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload

  deny.ip 的格式中也可以用 deny all;

  如果想实现这样的应用:除了几个 IP 外,其他全部拒绝,需要这样写:

allow 1.1.1.1;

allow 1.1.1.2;

deny  all;

  有时候会根据目录来限制 PHP 解析:

location ~ .*(diy|template|attachments|forumdata|attachment|image)/.*\.php$

{

      deny  all;

}

标题:LNMP--nginx 访问控制
作者:散宜生
地址:https://17kblog.com/articles/2018/02/17/1518840863733.html