我想在CakePHP中无限制地访问我的某个控制器。 以下是我正在使用的配置,遗憾的是,在尝试myhost.com/my_controller/my_action时,它仍然需要凭据。 / my_controller / my_action不应该匹配位置^〜/ my_controller / my_action 而不是位置〜.php $ ?
据我所知here它应该。
我尝试将上述技巧与 if($ request_uri~ * / phpmyadmin)结合使用,但IF中不允许使用auth_basic,我想(重启nginx:[emerg]:“auth_basic”指令是这里不允许)。
我还尝试匹配重写的位置,即位置/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
}
}
答案 0 :(得分:1)
通过将auth_basic
放在* .php位置,您可以说限制访问php生成的文件。如果您在控制器中访问一些php生成的文件,它将获胜。
此案例的最佳解决方案是将auth_basic
简单地放在location
之外。
编辑1:不要工作
server {
root
index
auth_basic "Restricted";
auth_basic_user_file
rewrite ^(.+)$ /index.php?q=$1 last;
location ^~ /my_controller/my_action {
auth_basic off;
fastcgi_pass
fastcgi_index
fastcgi_param
include
}
location ~ \.php$ {
fastcgi_pass
fastcgi_index
fastcgi_param
include
}
}
编辑1:完全重写
server {
root
index
auth_basic_user_file
rewrite ^(.+)$ /index.php?q=$1 last;
location / {
auth_basic "Restricted";
}
location ^~ /my_controller/my_action {
auth_basic off;
fastcgi_pass
fastcgi_index
fastcgi_param
include
}
location ~ \.php$ {
fastcgi_pass
fastcgi_index
fastcgi_param
include
}
}