解决kkfileview 使用https预览问题记录

**场景:**项目使用了开源的kkfileview进行文件在线预览,部署方式使用的是docker,使用IP进行访问,但是http协议直接访问有漏洞告警,现在需要调整为https,且仍然需要使用IP访问。

kkfileview官网kkFileView - 在线文件预览

问题:使用自签证书将web中间件访问方式调整为https,代理kkfile容器8012端口,后预览图片正常,预览其他类型文件提示如下错误

错误信息:

下载失败:org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://192.168.1.1:80/api/admin/image/local/c639a28c6e4b4278b8c93ff94352957a.txt": sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

解决方法:

1.重新自包含签证书SAN(Subject Alternative Name)的证书

bash 复制代码
openssl genrsa -out server.key 2048

cat >server.cnf<<EOF
[req]  
default_bits = 2048  
prompt = no  
default_md = sha256  
distinguished_name = dn  
req_extensions = req_ext  

[dn]  
C = CN  
ST = Province  
L = City  
O = Organization  
OU = Organizational Unit  
CN = test  

[req_ext]  
subjectAltName = @alt_names  

[alt_names]  
# 如果需要,可以添加更多的DNS或IP地址 
#DNS.1 = baidu.com   
IP.1 = 192.168.1.1
IP.2 = 192.168.1.2
EOF

openssl req -new -sha256 -key server.key -config server.cnf -out server.csr

openssl x509 -req -days 3650 -in server.csr -signkey server.key -extfile server.cnf -extensions req_ext -out server.crt

2.修改Dockerfile把证书加入到kkfile的jdk环境

bash 复制代码
cat >Dockerfile<<EOF
FROM keking/kkfileview:v4.4.0
MAINTAINER hello
ADD server.crt /opt/
RUN keytool -import -alias myServer -file /opt/server.crt -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt
ENTRYPOINT ["java","-Dfile.encoding=UTF-8","-Dspring.config.location=/opt/kkFileView-4.4.0-beta/config/application.properties","-jar","/opt/kkFileView-4.4.0-beta/bin/kkFileView-4.4.0-beta.jar"]
EOF

docker build -t keking/kkfileview:v4.4.1 .

3.使用新镜像重新启动kkfileview

bash 复制代码
docker stop kkfile && docker rm kkfile
docker run -d -p 8012:8012 -e KK_BASE_URL="https://192.168.1.1" --name kkfile keking/kkfileview:v4.4.1

4.替换web中间件的自签证书,重新加载web服务,验证预览

相关推荐
猿码优创3 分钟前
过滤境外ip和域名访问的解决方案
网络·网络协议·tcp/ip·安全·阿里云
北京耐用通信2 小时前
耐达讯自动化Profibus光纤链路模块:跨行业通信的“隐形桥梁”,让控制更丝滑!
人工智能·网络协议·自动化·信息与通信
归去来?2 小时前
记录一次从https接口提取25G大文件csv并落表的经历
大数据·数据仓库·hive·python·网络协议·5g·https
lkbhua莱克瓦242 小时前
深入理解HTTP协议:从理论到SpringBoot实践
网络·笔记·后端·网络协议·http·javaweb
newsxun3 小时前
从一条国道,到一个时代符号——申晨案例解析:如何打造公路文旅现象级IP「此生必驾318」
网络·网络协议·tcp/ip
Bruce_Liuxiaowei3 小时前
基于抓包分析的组播视频流故障排查与解决
网络·网络协议·wireshark·信号处理
2501_915909064 小时前
设置了 SSL Pinning 与双向 TLS 验证要怎么抓包
网络·网络协议·ios·小程序·uni-app·iphone·ssl
txinyu的博客4 小时前
HTTPS
网络协议·http·https
筱谙5 小时前
BES BLE低功耗蓝牙技术实现分析
服务器·网络·网络协议
2301_780789665 小时前
2025年UDP洪水攻击防护实战全解析:从T级流量清洗到AI智能防御
服务器·网络·人工智能·网络协议·安全·web安全·udp