一键操作只需要三步你就能拥有,做过两次,写个教程防止忘了
1.申请腾讯云上ssl证书,下载证书,选择tomcat(jks证书下载)
2. 代码配置
properties配置如下
#https server.port=8099 ----https配置端口 server.http.port=99 ----http配置端口 server.ssl.enabled=true server.ssl.key-store=classpath:XXXXX.jks ----下载的jks文件解压的 server.ssl.key-store-password=XXXXX -----密钥在解压的keystorePass.txt里 server.ssl.key-store-type=JKS server.ssl.redirect-enabled=true
增加代码配置支持https映射
package com.yxd.tiktok.stone.app.config;
import org.apache.catalina.connector.Connector;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.stereotype.Component;
@Component
public class HttpConfig implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
@Override
public void customize(TomcatServletWebServerFactory factory) {
Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
connector.setPort(99);
connector.setScheme("http");
connector.setSecure(false);
connector.setRedirectPort(8099);
factory.addConnectorCustomizers(c -> c.setAttribute("relaxedQueryChars", "{}[]|"));
factory.addAdditionalTomcatConnectors(connector);
}
}
jks文件放在这里
3.启动服务,postman模拟请求如下
4.分享一下腾讯云服务器可以买个服务器玩玩
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中
https://cloud.tencent.com/act/cps/redirect?redirect=2446&cps_key=37d1d896610894d81c571127d8004873&from=console