nginx作为静态文件代理服务器时,找不到文件会返回403错误页面,现将403错误页面转换为返回json数据返回。
设置location
location /download/v1 {
default_type application/octet-stream;
alias "D:/Program Files/download";
autoindex off;
autoindex_exact_size off;
add_header Content-Disposition "attachment;";
error_page 403 = @fetch;
}
location @fetch {
default_type application/json;
return 404 '{"status":404,"msg":"服务正在升级,请稍后再试……"}';
}
访问 /download/v1就会返回404错误json数据,
特别注意 autoindex off;代表是否列出目录,关闭状态,否则失效