【发布时间】:2017-10-11 11:12:06
【问题描述】:
我有一个服务器(nginx/1.6.0 PHP 5.5.14),这些设置可以正常工作。问题是当我使用location ^~ /sys/ 时,当我尝试访问 sys 文件夹时,它会下载索引。如果我删除 location ^~ / sys / 恢复正常工作。他的错误只发生在 php 文件中。 html文件正常工作。错误在哪里?
server {
server_name site.com;
root /home/www/site.com;
index index.php index.html index.htm;
location / {
index index.php index.html;
try_files $uri $uri/ /index.php;
}
location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/data/php5514/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_read_timeout 300;
include fastcgi_params;
}
location ^~ /sys/ {
}
}
我正在使用脚本,需要在 nginx 中进行此设置以保护文件夹免受未经授权的访问。
location ^~ /FOLDER/ {
if ($cookie_amember_nr !~* [a-zA-Z0-9]+) { #not authorized
rewrite ^(.*)$ http://EXAMPLE.COM/AMEMBER/protect/new-rewrite?f=FOLDERID&url=$request_uri?$args redirect;
}
set $file $document_root/AMEMBER/data/new-rewrite/$cookie_amember_nr-FOLDERID;
if (!-f $file) { #have not access
rewrite ^(.*)$ http://EXAMPLE.COM/AMEMBER/no-access/folder/id/FOLDERID?url=$request_uri?$args redirect;
}
#everything is ok
}
但是location ^ ~ 的这个问题不起作用。
【问题讨论】:
-
关于专业服务器或网络相关基础设施管理的问题对于 Stack Overflow 来说是无关紧要的,除非它们直接涉及编程或编程工具。您可以通过Server Fault 获得帮助。
标签: php nginx nginx-location php-5.4