Solved! add_header Content-Type "application/octet-stream"; set_by_lua $filename "return ngx.decode_base64(ngx.var['arg_f'])"; add_header Content-disposition "attachment; filename=\"$filename\""; Posted at Nginx Forum: http://forum.nginx.org/read.php?21,243816,243823#msg-243823