In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, Xiaobian will bring you about how to upgrade SpringBoot website to HTTPS. The article is rich in content and analyzes and narrates from a professional perspective. After reading this article, I hope you can gain something.
keytool -genkey -alias tomcat -dname "CN=Andy,OU=kfit,O=kfit,L=HaiDian,ST=BeiJing,C=CN" -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore keystore.p12 -validity 365
The meaning of each parameter of the command:
-genkey: generate key;
-alias: alias of key;
-dname: Specifies certificate owner information
-storetype: Keystore type is JCEKS. JKS(default),JCEKS(recommended),PKCS12,BKS,UBER. Each keystore can be only one of these types.
-keyalg: DSA or RSA algorithm (when using-genkeypair parameter), DES or DESede or AES algorithm (when using-genseckey parameter);
-keysize: The key length is between 512 and 1024 (multiples of 64)
-keystore: Name of the certificate repository
-validity: specifies how many days the certificate created is valid
Details of dname:
CN(Common Name)
OU(Organization Unit Name)
O(Organization name)
L(Locality city or region name)
ST(State or Province)
C(Country name)
Under directory C:\Users\current user you will see a file keystore.p12
Enable HTTPS in Spring Boot
Configure HTTPS in application.properties.
#https port number
server.port=81
#http port number
http-port=82
#Path to certificate.
server.ssl.key-store=classpath:keystore.p12
#Certificate password, please change it to your own certificate password
server.ssl.key-store-password=123456
#Keystore Type
server.ssl.keyStoreType=PKCS12
#Certificate alias
server.ssl.keyAlias=tomcat
Redirect HTTP requests to HTTPS
/**
* @ClassName : TomcatHttpConfig
* @Description :
* @Author : YWR
* @Date: 2021-01-12 22:56
*/
@Configuration
public class TomcatHttpConfig {
@Value("${http-port}")
private int port;
@Value("${server.port}")
private int sslPort;
@Bean
public ServletWebServerFactory 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(redirectConnector());
return tomcat;
}
private Connector redirectConnector() {
Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
connector.setScheme("http");
connector.setPort(port);
connector.setSecure(false);
connector.setRedirectPort(sslPort);
return connector;
}
}
The above is how to upgrade SpringBoot website to HTTPS shared by Xiaobian. If there is a similar doubt, please refer to the above analysis for understanding. If you want to know more about it, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.