hi, 看到了http://kovyrin.net/2010/07/24/nginx-fu-x-accel-redirect-remote/这篇文章后,我想通过ngx_lua与x-accel-redirect验证一下是否可以做一个下载代理,具体文件存在远程服务器上。下面是我的nginx配置,但是发现x-accel-redirect没有起到作用。我想知道是那篇文章介绍的有问题还是我自己配置的问题?
server {
listen 8083;
server_name a.com;
location /hello {
default_type 'text/plain';
content_by_lua '
ngx.exec("@bar");
';
}
location @bar {
content_by_lua '
ngx.header["X-Accel-Redirect"] = "/files/b.com/test.txt"
';
}
location ~* ^/files/(.*?)/(.*) {
internal;
set $download_uri $2;
set $download_host $1;
set $download_url http://$download_host/$download_uri;
proxy_set_header HOST $download_host;
proxy_set_header Authorization '';
proxy_hide_header content-Disposition;
add_header Content-Disposition 'attachment; filename="test.zip"';
proxy_max_temp_file_size 0;
proxy_pass $download_url;
}
access_log logs/batch/access.log main;
error_log logs/batch/error.log;
}
curl访问‘127.0.0.1:8083/hello’后,只能能得到以下信息
HTTP/1.1 200 OK
Date: Wed, 24 Dec 2014 07:40:20 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
X-Accel-Redirect: /files/b.com/test.txt
......
多谢