SpringBoot安装DigiCert证书配置https的教程

本文主要为大家分享SpringBoot安装DigiCert证书,并配置https的教程步骤,供大家参考!

一、购买DigiCert SSL证书

选择合适的DigiCert SSL证书类型,申请并成功颁发SSL证书。点此查看:DigiCert证书价格

二、SpringBoot安装DigiCert证书配置https步骤

1、将证书文件(DigiCert CA颁发证书的时候,会得到证书文件)复制到项目的根目录

2、配置文件

配置证书文件

3、配置http自动转向https

1)端口配置

http:

port: 8080

server:

port: 8443

2)端口监听转换

import org.apache.catalina.Context;

import org.apache.catalina.connector.Connector;

import org.apache.tomcat.util.descriptor.web.SecurityCollection;

import org.apache.tomcat.util.descriptor.web.SecurityConstraint;

import org.springframework.beans.factory.annotation.Value;

import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

@Configuration

public class HttpsConfig {

@Value(“${http.port}”)

private int httpPort;

@Value(“${server.port}”)

private int serverPort;

@Bean

public TomcatServletWebServerFactory servletContainer() {

TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory () {

@Override

protected void postProcessContext(Context context) {

SecurityConstraint securityConstraint = new SecurityConstraint();

securityConstraint.setUserConstraint(“CONFIDENTIAL”);

SecurityCollection collection = new SecurityCollection();

collection.addPattern(“/*”);

securityConstraint.addCollection(collection);

context.addConstraint(securityConstraint);

}

};

tomcat.addAdditionalTomcatConnectors(httpConnector());

return tomcat;

}

@Bean

public Connector httpConnector() {

Connector connector = new Connector(“org.apache.coyote.http11.Http11NioProtocol”);

connector.setScheme(“http”);

connector.setPort(httpPort);

connector.setSecure(false);

connector.setRedirectPort(serverPort);

return connector;

}

}

4、到此,SpringBoot成功安装DigiCert证书,接下来就可以使用https访问了。

免责声明:文章内容不代表DigiCert证书评测网的立场,本站不对其内容的真实性、完整性、准确性给予任何担保、暗示和承诺,仅供读者参考,文章版权归原作者所有。如本文内容影响到您的合法权益(内容、图片等),请及时联系本站,我们会及时删除处理。

为您推荐