nginx配置只能查看图片
1.在图片所在的目录下创建一个名为.htaccess’的隐藏文件,该文件用于设置禁止下载
2.在.htaccess文件中添加以下配置:
SetHandler default-handler
Options-Indexes
这样设置后,用户就无法通过点击链接或使用下载工具下载图片了
接下来,在 nginx的配置文件中添加以下配置
location /path/to/images/ {
add header Content-Disposition "inline";
add header Content-Type "image/jpeg";
}
此配置会为指定路径下的所有图片文件添加Content-Disposition’和Content-Type’头信息,使其只能在线查看。
最后,重启 nginx 服务器使配置生效
location /pic {
alias /data/;
proxy_connect_timeout 3;
proxy_read_timeout 3;
proxy_send_timeout 3;
autoindex on;
add_header Content-Disposition "inline";
add_header Content-Type "image/jpeg";
}
吾乃代码搬运工,侵联删
浙公网安备 33010602011771号