解决 iframe 预览 PDF 直接下载文件问题,可以在 nginx 服务器上进行配置,具体步骤如下:

  1. 打开 nginx 配置文件,一般在 /etc/nginx/nginx.conf 或 /usr/local/nginx/conf/nginx.conf 中。

  2. 在 http 块中添加以下代码:

location ~ \.pdf$ {
    add_header Content-Disposition 'inline';
}
  1. 保存配置文件并重启 nginx 服务。

经过以上配置,nginx 服务器会在响应头中添加 Content-Disposition: inline,告诉浏览器以内联方式打开 PDF 文件,而不是直接下载文件。这样就可以在 iframe 中预览 PDF 文件了。

Nginx 服务器配置解决 iframe 预览 PDF 直接下载问题

原文地址: https://www.cveoy.top/t/topic/ng08 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录