Skip to content

Instantly share code, notes, and snippets.

@mylxsw
mylxsw / nginx-lua-firefox-filedownload.conf
Last active December 26, 2023 02:37
nginx+lua解决不同浏览器文件下载兼容性,解决文件乱码问题
location /download/ {
root /home/data/images;
if ($request_uri ~* ^.*\/(.*)\.(doc|txt|zip|jpg|jpeg|png|gif|pdf|rar|xls|xlsx|docx|ppt|pptx|wps)(\?name=([^&]+))$) {
set $filename "$arg_name.$2";
header_filter_by_lua_block {
if ngx.status ~= 200 then
return
end
local ua = ngx.req.get_headers()["User-Agent"]