Redirect nginx和cookie重定向

Redirect nginx和cookie重定向,redirect,cookies,nginx,config,Redirect,Cookies,Nginx,Config,我需要一些nginx PRO来帮我解决这个问题。我有一个秘密页面在我的网站,我需要保护从扫描机器人和暴力(实际上这是登录页面)。我需要重定向任何人到404页,如果有人试图访问这个页面没有特殊的cookie。我需要这个页面工作非常好,如果饼干设置。让我们看看我的配置: server { listen 80; server_name example.com; root /var/www/example.com/; index

我需要一些nginx PRO来帮我解决这个问题。我有一个秘密页面在我的网站,我需要保护从扫描机器人和暴力(实际上这是登录页面)。我需要重定向任何人到404页,如果有人试图访问这个页面没有特殊的cookie。我需要这个页面工作非常好,如果饼干设置。让我们看看我的配置:

server {
        listen  80;
        server_name  example.com;
        root   /var/www/example.com/;
        index  index.php;
        client_max_body_size 64M;

        location ~* /(secret\-page\.php/).*$ {
#                if ($cookie_secretauth != "123123") {
                        rewrite ^/(.*)$ /not-found;
#                }
        }

        location / {
                if (!-e $request_filename) {
                    rewrite ^/(.*)$ /index.php last;
                }
        }

        location ~* ^/(images|data|t)/.+.(js|css|png|jpg|jpeg|gif|ico)$ {
                access_log        off;
                expires max;
        }

        location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                #.....more things
        }
}
请看注释行。注释掉这些行后,重定向工作正常。一旦我删除注释,它就变成下载我的PHP代码而不是重定向我!我做错了什么?我的头断了


谢谢。

必须在
secret page.PHP
位置中添加PHP处理程序,以便将其传递给PHP

server {
    listen  80;
    server_name  example.com;
    root   /var/www/example.com/;
    index  index.php;
    client_max_body_size 64M;

    location ~* /(secret\-page\.php/).*$ {
            if ($cookie_secretauth != "123123") {
                    rewrite ^/(.*)$ /not-found;
            }
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #.....more things
    }

    location / {
            if (!-e $request_filename) {
                rewrite ^/(.*)$ /index.php last;
            }
    }

    location ~* ^/(images|data|t)/.+.(js|css|png|jpg|jpeg|gif|ico)$ {
            access_log        off;
            expires max;
    }

    location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #.....more things
    }
}

有一个比较大的街区。。为什么我要重复这个街区?看,有一个重写到index.php的块,location~\.php在它正常运行之后执行。