nginx内容处置头不工作
您好,我正在nginx配置中为pdf添加_头。我希望浏览器提供pdf内联服务,但它正在为用户下载文件。 我的配置文件中有这个nginx内容处置头不工作,nginx,header,Nginx,Header,您好,我正在nginx配置中为pdf添加_头。我希望浏览器提供pdf内联服务,但它正在为用户下载文件。 我的配置文件中有这个 location ~* /(.*\.pdf) { types { application/octet-stream .pdf; } default_type application/octet-stream; add_header Content-Disposition "inline"; } 我还尝试了
location ~* /(.*\.pdf) {
types { application/octet-stream .pdf; }
default_type application/octet-stream;
add_header Content-Disposition "inline";
}
我还尝试了以下add_头语法
添加标题内容处置:内联;
及
添加标题内容处置:“内联”
如果可以的话,请帮忙。我在配置文件中也有以下内容
location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}
location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
expires off; ## Do not cache dynamic content
fastcgi_pass 127.0.0.1:9000;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
我使用了下面的语法和fireforx修复程序(在评论中提到)来修复这个问题。
位置~*.pdf${
如果($uri~“^/upload/(.+.pdf)$”){
设置$filename$1;
}
添加标题内容处置“内联;文件名=$filename”;
}为什么强制键入
应用程序/octet流
?使用标准的application/pdf
。浏览器不知道如何处理application/octet流
文件类型,因此它唯一的选择是下载文件,而不关心内容配置
标题。感谢您的提示,但它仍在下载。我们是否需要在浏览器上显示一些内联内容?位置~*/(.\.pdf){types{application/pdf.pdf;}添加标题内容处置:inline;}它取决于浏览器。正如我前面所说的,如果浏览器不知道如何处理这个文件,它会下载这个文件。您的浏览器是否从其他来源打开pdf?酷,现在可以使用了。根据你的建议,我检查了浏览器的此设置。选项>应用程序>在pdf内容类型>中选择firefox中的预览