# nginx+php限制某个IP访问



> 环境： php7.2+nginx1.2+redis5+mysql8
>
> 框架: Thinkphp
>
> 需求： 针对后台进行限制: http://xxx/ViQzauWTty.php/login/index
>
> 发现访问：xxxx.php 路由自动加上 /login/index 路径

```nginx
location ~ .*xxxx.* {

        allow 127.0.0.1/8;
        deny all;

        # 你原PHP文件配置复制一份
        location ~ [^/]\.php(/|$)
        {
                try_files $uri =404;
                fastcgi_pass  unix:/tmp/php-cgi-72.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
                include pathinfo.conf;
        }

    }
```
