liwya 发表于 2018-11-12 07:53:40

nginx-----nginx针对某个url限制ip访问,常用于后台访问限制

  假如我的站点后台地址为: http://www.abc.net/admin.php 那么我想限制只有个别ip可以访问后台,那么需要在配置文件中增加:
  1
  2   location ~ .*admin.* {
  3         allow 1.1.1.1;
  4         allow 12.12.12.0/24;
  5         deny all;
  6         location ~ \.php$ {
  7         include fastcgi_params;
  8         fastcgi_passunix:/tmp/php-fcgi.sock;
  9         fastcgi_index index.php;
  10         fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
  11         }
  12   }
  复制代码
  需要注意的是,在这个location下也得加入php解析相关的配置,否则php文件无法解析。

页: [1]
查看完整版本: nginx-----nginx针对某个url限制ip访问,常用于后台访问限制