我使用module.html Nginx安全链接模块来保护静态文件下载。对于静态文件,它工作得很好。
但是,当我试图用php文件实现这一点时,它不起作用。基本上,我是通过ajax请求使用它的,如
http://www.example.com/dev/serve.php?h=hash&t=timestamp当我在下面检查时,虽然它没有哈希和时间戳,但是它是不受任何限制的。
http://www.example.com/dev/serve.php对于静态文件,它正常工作,即在访问没有散列的任何图像时,将返回指定的错误请求响应的时间戳:
http://www.example.com/dev/image.png服务器Config:
#
# The default server
#
server {
listen 80;
server_name www.example.com;
location / {
root /box;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /box;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /box;
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /dev/ {
root /box;
secure_link $arg_h,$arg_s;
secure_link_md5 "secret$uri$secure_link_expires$remote_addr";
if ($secure_link = "") {
return 403;
}
if ($secure_link = "0") {
return 410;
}
}
}我的问题:
发布于 2015-02-12 15:31:43
过了一会儿,我找到了解决办法:
#
# The default server
#
server {
listen 80;
server_name www.example.com;
location / {
root /box;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /box;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /box;
secure_link $arg_h,$arg_s;
secure_link_md5 "secret$uri$secure_link_expires$remote_addr";
if ($secure_link = "") {
return 403;
}
if ($secure_link = "0") {
return 410;
}
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}请注意,这个解决方案是针对php文件的,很少修改它也适用于其他文件。
https://stackoverflow.com/questions/27468743
复制相似问题