您的位置:首页 > 运维架构 > Nginx

nginx配置的一点问题

2016-07-21 14:43 507 查看
工作原因,需要在原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