【发布时间】:2011-05-14 11:17:39
【问题描述】:
我想在 CakePHP 中不受限制地访问我的控制器之一。 下面是我正在使用的配置,不幸的是,在尝试 myhost.com/my_controller/my_action 时它仍然需要凭据。 /my_controller/my_action 不应该匹配 location ^~ /my_controller/my_action 而不是 location ~ .php$?
根据我对here 的理解,应该。
我试图将上述技巧与 if ($request_uri ~* /phpmyadmin) 结合起来,但 auth_basic 在 IF 中是不允许的,我猜(重启 nginx: [emerg]: "auth_basic" 指令是这里不允许)。
我也尝试匹配重写的位置,即 location /index.php?q=/my_controller/my_action { 但没有成功。
我猜,由于重写,精确运算符“=”也不能正常工作。 “~”也一样。
理想情况下,解决方案应该足够通用,也可以与其他控制器一起使用。
server {
root
index
rewrite ^(.+)$ /index.php?q=$1 last;
location ^~ /my_controller/my_action {
auth_basic off;
fastcgi_pass
fastcgi_index
fastcgi_param
include
}
location ~ \.php$ {
auth_basic "Restricted";
auth_basic_user_file
fastcgi_pass
fastcgi_index
fastcgi_param
include
}
}
【问题讨论】: