工作原因,需要在原nginx server中增加下载的功能,将nginx.conf中的server配置增加如下配置:
下载文件的目录放在项目根目录下的download下:
if ( $uri ~* "^/download/.*" ) {
break;

}

这里break是跳过之后的rewrite规则,直接执行后面的location。然后在增加匹配download的location,这个location要放在 匹配所有的 location / 之前。

location ~* "^/download/.*" {
root /data1/www/htdocs/buy.sc.weibo.com/;
add_header Content-Disposition 'attachment;';
add_header Content-Type 'application/octet-stream; charset=utf-8';
add_header Content-Transfer-Encoding 'binary';
error_page 404 http://weibo.com/sorry;
}

add_header可以指定 response的header头部信息。
匹配到一个location之后,就不会继续匹配了。

以上就介绍了 nginx配置的一点问题,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

09-11 18:20