【解决方案】SpringBoot项目添加ssl证书后不生效问题

SpringBoot项目添加ssl证书后不生效问题

在我的网站中添加证书后报错,不是打包失败,就是证书添加后启动失败,亦或者是前端页面请求后端地址失败。

解决方案

. 打包报错

报错:
bash 复制代码
(default-resources) on project pig-boot: filtering G:\INFINITE-SISM\cursor\mysite\platform-irule - cursor\pig-boot\src\main\resources\liufei.xyz.pfx to G:\INFINITE-SISM\cursor\mysite\platform-irule - cursor\pig-boot\target\classes\liufei.xyz.pfx failed with MalformedInputException: Input length = 1 -> [Help 1]
原因:

springboot编译resource中二进制文件导致的报错。

解决方案:

在pom.xml中添加以下内容:

bash 复制代码
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<configuration>
					<!-- SSL 密钥库是二进制文件,必须禁止 Maven 资源过滤 -->
					<nonFilteredFileExtensions>
						<nonFilteredFileExtension>pfx</nonFilteredFileExtension>
						<nonFilteredFileExtension>p12</nonFilteredFileExtension>
						<nonFilteredFileExtension>jks</nonFilteredFileExtension>
					</nonFilteredFileExtensions>
				</configuration>
			</plugin>

.证书报错

报错
bash 复制代码
Unable to create key store: Could not load store from 'classpath:game.*.xyz.pfx'
DerInputStream.getLength(): lengthTag=111, too big.
原因:

resource中的证书文件与target中的证书文件不一致,文件被当成文本编译。

解决方案:

在pom.xml中添加以下内容:

bash 复制代码
			
		<resources>
			<resource>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
				<excludes>
					<exclude>ssl/**</exclude>
				</excludes>
			</resource>
			<resource>
				<directory>src/main/resources</directory>
				<filtering>false</filtering>
				<includes>
					<include>ssl/**</include>
				</includes>
			</resource>
		</resources>

.前端访问接口报错

报错
bash 复制代码
Unable to create key store: Could not load store from 'classpath:game.*.xyz.pfx'
DerInputStream.getLength(): lengthTag=111, too big.
原因:

HTTPS 会校验证书域名。你的证书只包含:

.xyz
www.
.xyz

不包含 127.0.0.1

解决方案:

在vite.config.js的转发中配置允许非 HTTPS 连接:

bash 复制代码
    proxy: {
        '/api': {
          target: env.VITE_ADMIN_PROXY_PATH, 
          ws: true,  
          changeOrigin: true,  
          secure: false 
相关推荐
子兮曰1 天前
jev-ultrafast 深度解析:7 秒订机票的浏览器 Agent 是如何炼成的
前端·后端·agent
子兮曰1 天前
Jev 爆发一周:7 秒 Agent 背后的 System One 生态与三场争议
前端·后端·ai编程
爱勇宝1 天前
ZCode 开源 24 小时:一份没有历史的账本,回答不了"有没有偷代码"
前端·后端·chatglm (智谱)
胡写代码1 天前
别再前后端各写一套表单校验了
java·后端
大勇前进1 天前
原生 PHP 还是 Laravel?小项目到底要不要上框架
后端
vipxieliang1 天前
ValidX 在 DDD 领域驱动设计中的实践
java·spring boot
yuzhi_liu1 天前
我用 LangGraph4j 实现 Multi-Agent Supervisor
后端
alsmile1 天前
Node-RED 之外,国产规则引擎的新方案:基于标准语法,Go 先行实现
后端·开源·go
大白801 天前
PHP 内存溢出排查思路:看懂报错日志,精准定位问题
后端
二月龙1 天前
PHP 接口返回统一响应封装,让前后端对接更省心
后端