已解决:在 vps linux 服务器上还需要设置什么以允许 https 进行 Spring 启动

问题描述 投票:0回答:1

我正在 VPS 虚拟服务器(ubuntu)上运行 spring-boot jar 应用程序,并且面临证书未知问题。我几乎尝试了一切,但没有成功。

  1. 当我使用 http 配置文件运行 jar (spring-boot) 并在 http 模式下托管时,就可以正常工作了。所以我知道连接是正确的
  2. 当我使用 https 地址从邮递员调用 vps 上的 spring-boot 时,也可以正常工作。
  3. 最后,现在以 https 模式托管时,调用 spring-boot 以 server.ssl.enabled=true 运行,然后在日志中出现错误 =>
    onUncaughtException(SimpleConnection{channel=[id: 0x4e6d10c4 ..... Caused by:  javax.net.ssl.SSLHandshakeException: **Received fatal alert: certificate_unknown
    **

我有来自域的可信证书,我也有中间证书。两者均导入到我的 keystore-certificate.p12 文件中,该文件的地址为

application.properties like this
server.ssl.key-store-type=PKCS12
server.ssl.key-store=/root/myfolder/keystore-certificate.p12
server.ssl.key-store-password=keystore-password
server.ssl.enabled=true

首先导入中间证书,其次导入域证书。证书有效,我已经检查过,所以我不知道什么会导致问题。托管已正确设置 https 协议,因此我可以从 url 中的图标查看证书详细信息。当我从托管发送请求时,这是在标头中

Accept:
application/json, text/plain, */*
Referer:
https://dev-environment.hosting.fun/

Request URL:
https://ipaddress:8080/
Referrer Policy:
strict-origin-when-cross-origin

在 vps 上有允许 8080 的端口,我已经检查过了,我还添加了权限

块引用

密钥库证书.p12

块引用

确保 spring-boot 能够读取内容。

为了获得证书,我使用了 -

sudo certbot certonly --manual --preferred-challenges=dns -d hosting.fun -d dev- 
environment.hosting.fun

,然后将其转换为pk12文件,然后导入到keystore-certificate.p12中。

我还缺少什么?

linux spring-boot https certificate vps
1个回答
0
投票

所以,如果有人没有像我这样丰富的经验,这解决了我的问题。

我正在调用 https 不允许的 IP 地址,其中证书中没有 IP 地址,但 CN = 托管的通用名称或其他名称(如果您添加它们)。

因此,您需要在您的主机上设置 DNS 记录,您将在其中添加您尝试调用的远程服务器的 IP 地址和名称,这将反映证书中的名称。那么,您的 Angular 或其他应用程序将不会调用 https://ipaddress,而是调用 https://dev-hosting.com

© www.soinside.com 2019 - 2024. All rights reserved.