1. Nginx 配置中重复添加了 Content-Disposition
检查你的 Nginx 配置文件,是否在多个地方设置了 add_header Content-Disposition ...
location /files/ {
add_header Content-Disposition 'inline';
# 其他配置...
}
# 或者在 server 块或其他 location 中又加了一次
location / {
add_header Content-Disposition 'inline'; # ❌ 重复!
}
解决办法
确保在整个配置中,Content-Disposition 只被设置一次。使用 grep 检查:
grep -r "Content-Disposition" /etc/nginx/
删除或注释掉重复的设置。
2. 后端应用(如 PHP、Node.js、Java 等)也返回了 Content-Disposition
这是最常见的原因!
如果你的 Nginx 是反向代理(proxy_pass),而后端服务(如 Spring Boot、PHP 脚本)本身也设置了 Content-Disposition: inline,那么 Nginx 再用 add_header 添加一次,就会导致两个相同的 header。
解决办法
在 Nginx 中清除后端返回的该 header,然后重新设置:
location /files/ {
proxy_pass http://backend;
# 清除后端返回的 Content-Disposition
proxy_hide_header Content-Disposition;
# 再由 Nginx 设置
add_header Content-Disposition 'inline';
}
关键指令:proxy_hide_header Content-Disposition;
这样就能避免重复。