nginx autoindex目录列表功能下载txt文件时文件直接在浏览器打开而非下载

该博客内容涉及Web服务器配置,主要讲解如何在location块中设置规则,当用户请求特定文件类型(如txt, doc, pdf等)时,服务器将自动以附件形式下载这些文件,并设置相应的内容类型。通过添加Content-Disposition和Content-Type头,确保文件以安全方式传递。
摘要由CSDN通过智能技术生成
       location / {
		    if ($request_filename ~* ^.*?.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$)
            {
				add_header Content-Disposition 'attachment';
                add_header Content-Type: 'APPLICATION/OCTET-STREAM';
            }

			autoindex on;
            root   html;
            index  index.html index.htm;
        }

在location中添加如下内容

if ($request_filename ~* ^.*?.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$)
            {
                add_header Content-Disposition 'attachment';
                add_header Content-Type: 'APPLICATION/OCTET-STREAM';
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值