1.目的
预览图片、pdf、txt
2.配置
#搭建文件预览
server {
listen 8888;
server_name preview.xxx.com;
location ^~ /preview/ {
alias D:/data/; #不同OS键入对应path即可
if ($request_filename ~* ^.*?\.(html|doc|zip|docx)$) {
add_header Content-Disposition attachment;
add_header Content-Type application/octet-stream;
}
sendfile on; # 开启高效文件传输模式
autoindex on; # 开启目录文件列表
autoindex_exact_size on; # 显示出文件的确切大小,单位是bytes
autoindex_localtime on; # 显示的文件时间为文件的服务器时间
charset utf-8,gbk; # 避免中文乱码
}
}
3.访问示例路径
访问目录文件列表以及根据文件名称预览文件
http://localhost:8888/preview/http://localhost:8888/preview/1.jpg