工作原因,需要在原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;
}
以上就介绍了 nginx配置的一点问题,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号