静态pdf文件,目的是让网页直接提示用户保存
配置如下:
location ~ /sync/dl/[0-9]+/(.+)\.pdf {
more_set_headers "Content-Type:application/octet-stream";
more_set_headers "Content-Disposition: attachment;filename=$1";
more_clear_headers "Location";
alias /opt/track/data/;
}
输出确实 301 并且location 多一个 /
[root@HZ4 ~]# curl -I "http://192.168.0.17/sync/dl/18/4201E7A296C640270C7d57g0.pdf"
HTTP/1.1 301 Moved Permanently
Server: nginx/1.3.10
Date: Mon, 21 Jan 2013 07:39:21 GMT
Content-Type: application/octet-stream;
Content-Length: 185
Location: http://192.168.0.17/sync/dl/18/4201E7A296C640270C7d57g0.pdf/
Connection: keep-alive
Content-Disposition: attachment;filename=4201E7A296C640270C7d57g0.pdf
如果不用正则式匹配,可以网页正常提示用户保存,但是文件名只能写死
location /sync/dl {
more_set_headers "Content-Type:application/octet-stream";
more_set_headers "Content-Disposition: attachment;filename=1.pdf";
alias /opt/track/data/;
}
返回200 但是文件名只能写死
[root@HZ4 ~]# curl -I "http://192.168.0.17/sync/dl/18/4201E7A296C640270C7d57g0.pdf"
HTTP/1.1 200 OK
Server: nginx/1.3.10
Date: Mon, 21 Jan 2013 07:49:14 GMT
Content-Type: application/octet-stream
Content-Length: 814419
Last-Modified: Fri, 11 Jan 2013 08:28:59 GMT
Connection: keep-alive
ETag: "50efcd4b-c6d53"
Content-Disposition: attachment;filename=1.pdf
Accept-Ranges: bytes