In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to configure https using SpringBoot. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
SpringBoot configuration https (SSL Certificate)
Being WeChat Mini Programs recently, https is a must.
It only takes three steps.
SpringBoot2.x version
Isn't it inexplicably nice to compare this little lock?
Because there was a domain name on the record a long time ago, I directly applied for the SSL certificate and came down in a few minutes.
1. Put the .jks file in the tomcat directory
Copy to the project (pay attention to the path)
two。 Configure application.yml ssl: key-store: classpath:server.jks key-store-password: password keyStoreType: JKS set when you apply
3. And then there's the redirection.
Add under the startup class; (redirect the specified http8080 port to https8888)
@ Bean public ServletWebServerFactory servletContainer () {TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory (); tomcat.addAdditionalTomcatConnectors (createHTTPConnector ()); return tomcat;} private Connector createHTTPConnector () {Connector connector = new Connector ("org.apache.coyote.http11.Http11NioProtocol"); / / enable both http (8080) and https (8443) connector.setScheme ("http"); connector.setSecure (false) Connector.setPort (8080); connector.setRedirectPort (443); return connector;}
Ok
SpringBoot is transformed into https access
SpringBoot https transformation
1. Generate key certificate
Generate command: keytool-genkey-alias tomcat-storetype PKCS12-keyalg RSA-keysize 2048-keystore keystore.p12-validity 3650
(1) keyword explanation:
Alias: key alias
Storetype: specifies the KeyStore type
Keyalg: the name of the algorithm for the health certificate. RSA is an asymmetric encryption algorithm.
Keysize: certificate size
Keystore: the storage path of the generated certificate file
Validity: the validity period of the certificate
(2) Note for generating certificate:
After entering the certificate generation command, you are prompted to enter:
KeyStore password: certificate password, used when configuring certificates in later projects
Last name: generally useless, when you view the certificate in the browser, it will show that the certificate for formal occasions still needs to fill in the standard.
Organizational unit: certificate user information is generally useless. When you view the certificate in the browser, it will show that the certificate for formal occasions still needs to fill in the standard.
Organizational unit name: the certificate uses the unit name, which is generally useless. When you view the certificate in the browser, it will show that the certificate for formal occasions still needs to fill in the standard.
The name of the city or region in which it is located: it is displayed when the certificate information is viewed in the browser.
The name of the province / municipality in which it is located: it will be displayed when the certificate information is viewed in the browser.
The double-letter country code of the unit: the country code, which is displayed when viewing certificate information in the browser.
two。 Copy the generated key certificate to the resource in the project
You can also configure the absolute path of the key certificate without copying it to the project.
3. Modify the project configuration file application.properties
Add the following configuration items:
Server.ssl.key-store=classpath:keystore.p12 (key file path, or you can configure an absolute path)
Server.ssl.key-store-password=aqjcpt (KeyStore password entered when the key is generated)
Server.ssl.keyStoreType=PKCS12 (key type, consistent with key generation command)
Server.ssl.keyAlias=tomcat (key alias, consistent with key generation command)
4. Start the project and access the project directly
Thank you for reading! This is the end of this article on "how to configure https with SpringBoot". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
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.