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

假如我的站点后台地址为: http://www.abc.net/admin.php 那么我想限制只有个别ip可以访问后台,那么需要在配置文件中增加:

    location ~ .*admin.* {
        allow 1.1.1.1;
        allow 12.12.12.0/24;
        deny all;
        location ~ .php$ {
        include fastcgi_params;
        fastcgi_pass  unix:/tmp/php-fcgi.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
        }
    }

需要注意的是,在这个location下也得加入php解析相关的配置,否则php文件无法解析。

转自

nginx针对某个url限制ip访问,常用于后台访问限制 - flyoss - 博客园 https://www.cnblogs.com/flying1819/articles/9162332.html

原文地址:https://www.cnblogs.com/paul8339/p/11550736.html