背景
我正在使用Nginx和mod_zip(http://wiki.nginx.org/NgxZip,在Github here上)作为代理,将数据从亚马逊的S3流式传输到存档中 .
mod_zip采用以空格分隔的参数的清单 . 换行符分隔新文件 . 每行的格式为: CRC[- for unknown] size location filename
Example of a two-line manifest :
- 4 /pro-core.com/prostore/9228407_foobar.txt?AWSAccessKeyId=key&Expires=sometime&Signature=signed foo/foobar.txt
- 288134 /pro-core.com/prostore/9228400_38.png?AWSAccessKeyId=key&Expires=soon&Signature=signed bar/38.png
这将创建一个包含2个目录的存档:
|- foo
| |- foobar.txt
|- bar
|- 38.png
My nginx.conf file :
用户nginx; worker_processes 1; error_log /usr/local/nginx/logs/error.log debug; events {worker_connections 1024; } http {include mime.types; default_type application / octet-stream; #access_log logs / access.log main;
keepalive_timeout 0;
sendfile off;
gzip off;
服务器{
听8008;
server_name localhost;
#charset koi8-r;
#access_log logs / host.access.log main;
root html;
地点 / {
内部;
}
location /pro-core.com/ {
内部;
proxy_pass http://s3.amazonaws.com;
proxy_buffering off;
proxy_buffers 2 4m;
proxy_buffer_size 4m;
proxy_busy_buffers_size 4m;
}
location / download / {
proxy_pass http:// localhost:3000 / utilities / s3_manifest_for_nginx_to_zip_and_stream /;
proxy_redirect off;
proxy_buffering off;
proxy_set_header主机$ host;
proxy_set_header X-Real-IP $ remote_addr;
proxy_set_header Accept-Encoding标识;
}
}
}
问题
mod_zip似乎用括号做了一些有趣的事情 . 我的一些S3键中有括号,如 9228403_foobar (1).txt
. 我无法更改S3键 . 在清单中,我有一行看起来像:
- 4 /pro-core.com/prostore/9228403_foobar%20%281%29.txt?AWSAccessKeyId=key&Expires=time&Signature=signed foo/foobar _1_.txt
请注意,位置网址已转义 . 当我尝试打开生成的存档时,它已损坏 . 伤心的熊猫 . 查看nginx错误日志,我从S3获取了一个403,其中包含密钥中的parens文件:
From nginx log :
"GET /pro-core.com/prostore/9228403_foobar%20(1).txt?AWSAccessKeyId=key&Expires=time&Signature=signed HTTP/1.0
...
[debug] : *31 http proxy status 403 "403 Forbidden"
请注意,位置URL中的parens不再被转义 . 我通过curl执行了一个vanilla“GET”验证了URL是问题 .
$ curl -v http://s3.amazonaws.com/..._foobar%20(1).txt?...
=> 403 Forbidden -- SignatureDoesNotMatch
$ curl -v http://s3.amazonaws.com/..._foobar%20%281%29.txt?...
=> 200 OK -- contents of foobar (1).txt
问题
有没有办法在我的应用程序中更改某些内容,或者告诉nginx或mod_zip不要取消我的URL?
2 回答
我有一个解决方法,我的问题是从S3键中删除括号 . 它并不理想,但它现在解决了我们的问题 .
Nginx将解码传递给代理传递的uri,从而中断对s3的调用 .