假如我的站點后台地址為: 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