解决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服务,验证预览

相关推荐
老蒋新思维25 分钟前
创客匠人峰会深度解析:智能体驱动知识变现的数字资产化路径 —— 创始人 IP 的长期增长密码
人工智能·网络协议·tcp/ip·重构·知识付费·创始人ip·创客匠人
老蒋新思维3 小时前
创客匠人峰会实录:创始人 IP 变现的 “人 + 智能体” 协同范式 —— 打破知识变现的能力边界
大数据·网络·人工智能·网络协议·tcp/ip·创始人ip·创客匠人
2501_916007473 小时前
TCP 抓包分析实战,从三次握手到自定义协议解析的完整方法
网络协议·tcp/ip·ios·小程序·uni-app·php·iphone
老蒋新思维5 小时前
创客匠人启示录:AI 时代知识变现的底层逻辑重构 —— 从峰会实践看创始人 IP 的破局之路
网络·人工智能·网络协议·tcp/ip·数据挖掘·创始人ip·创客匠人
码农爱学习5 小时前
使用wpa工具配网、udhcpc分配IP的过程分析
网络·网络协议·tcp/ip
北京耐用通信6 小时前
协议转换的‘魔法转换器’!耐达讯自动化Ethernet/IP转Devicenet如何让工业机器人‘听懂’不同咒语?”
网络·人工智能·科技·网络协议·机器人·自动化·信息与通信
CAir28 小时前
一问读懂并了解HTTP代理的基本原理
网络·网络协议·http·代理
北京耐用通信8 小时前
阀岛的“超级大脑”:耐达讯自动化网关让EtherNet/IP转DeviceNet“说同一种语言”
人工智能·物联网·网络协议·网络安全·自动化·信息与通信
卓码软件测评8 小时前
具有CMA和CNAS双重资质的软件测试机构【Gatling脚本开发资源请求处理:html、css、js自动下载配置】
websocket·网络协议·测试工具·单元测试·测试用例
喜欢流萤吖~10 小时前
POST 与 GET:HTTP 请求方法的本质区别
网络·网络协议·http