SpringBoot配置阿里云SSL免费证书

下载阿里云免费的ssl证书,以下是Tomcat配置

里面有两个文件一个是pfx一个是密码txt文件,把密码复制出来。放到resources下
yml

http:
  port: 8081
server:
  # 服务器的HTTP端口,默认为80
  port: 443
  ssl:
    key-store: classpath:
    key-store-password: 
    keyStoreType: 

Config配置文件

@Configuration
public class TomcatConfig {

    @Value("${http.port}")
    private int httpPort;

    @Bean
    public ServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
        tomcat.addAdditionalTomcatConnectors(createStandardConnector()); // 添加http
        return tomcat;
    }

    // 配置http
    private Connector createStandardConnector() {
        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setPort(httpPort);//nginx需要代理的端口,这里的端口是yml文件中的8080端口
//        connector.setSecure(false);
        connector.setScheme("http");
        connector.setRedirectPort(443); // 当http重定向到https时的https端口号
        return connector;
    }

你可能感兴趣的:(SpringBoot配置阿里云SSL免费证书)