Php 使用nginx限制对管理模块的访问并不总是有效

Php 使用nginx限制对管理模块的访问并不总是有效,php,zend-framework,nginx,Php,Zend Framework,Nginx,我需要限制在我的网站管理模块。不幸的是,它并不总是起作用。我正在从apache迁移到nginx,我的nginx配置是 server { listen 80; server_name example.com; charset utf-8; index index.php; root /websites/example/www/; location /admin { allow 192.168.3.137;

我需要限制在我的网站管理模块。不幸的是,它并不总是起作用。我正在从apache迁移到nginx,我的nginx配置是

server {

    listen 80;
    server_name example.com;

    charset utf-8;

    index index.php;

    root /websites/example/www/;

    location /admin {
            allow 192.168.3.137;
            deny all;

            try_files $uri /index.php;
    }

    location / {
            try_files $uri /index.php;
    }

location ~* \.php$ {


        fastcgi_pass unix:/var/run/php5-fpm.sock;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        fastcgi_param APPLICATION_ENV dev;

        include fastcgi_params;
    }

当我尝试在Firefox中打开/时,我会被重定向到我的主页。如果url没有尾部斜杠,则会打开正确的管理员登录。在这种情况下,访问日志只有“/”的记录(主页)。我在Chrome和IE上没有问题。我在php应用程序中使用Zend Framework。

所有以
.php
结尾的文件都由
location~*\.php$
块处理,它有效地绕过了
location/
块中的访问规则

一种方法可能是使用嵌套的位置块并复制PHP块。例如:

location / {
    try_files $uri /index.php;
}

location ~* \.php$ {
    include fastcgi_params;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param APPLICATION_ENV dev;
}

location ^~ /admin {
    allow 192.168.3.137;
    deny all;

    try_files $uri /admin/index.php;

    location ~* \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param APPLICATION_ENV dev;
    }
}
^ ~
修饰符确保
位置
块处理以
/admin
开头的所有URI。嵌套的
位置
块继承了
允许/拒绝
规则

要管理重复的代码,您可能需要将
fastcgi
指令卸载到单独的文件中,并
将它们包含到每个位置

有关更多信息,请参阅。

谢谢您的回复。 我删除了FF cookies和缓存,问题就解决了