Springboot內建tomcat配置HTTPS證書
1.生成SSL證書
2.把證書放到專案根目錄下面,比如我之前給安信SSL網站安裝證書的時候,就放在:
3.把證書再放到專案resources目錄下,與application.properties同一目錄,然後修改application.properties檔案,新增HTTPS支援。在application.properties中新增如下程式碼:
Server:
Port:443指定https埠號
Server:
Key-store證書名稱
Key-alias別名
Key-store-type證書型別
Key-store-password證書密碼
Enabled: true允許透過https請求
4.在配置類中新增如下程式碼:
package com.bootdo.common.config;
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.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class HttpsConfig {
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
@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(getHttpConnector());
return tomcat;
}
private Connector getHttpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(80);
connector.setSecure(false);
connector.setRedirectPort(443);
return connector;
}
public void customize(ConfigurableEmbeddedServletContainer container) {
container.setPort(443);
}
}
5.上傳到伺服器的話,要在伺服器放jar包的地方壓放入證書檔案:
文章來源:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69900059/viewspace-2638171/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 詳解如何給Tomcat配置Https/ssl證書TomcatHTTP
- Nginx 配置https證書NginxHTTP
- HTTPS的SSL證書配置HTTP
- Tomcat 安裝SSL證書 – HTTPS SSL 教程TomcatHTTP
- 區域網/內網IP地址配置https證書教程內網HTTP
- Keytool配置 Tomcat的HTTPS雙向認證TomcatHTTP
- Apache 配置https 自簽名證書 或者 購賣證書ApacheHTTP
- springboot 配置 httpsSpring BootHTTP
- 在本地環境配置 https 證書(mac)HTTPMac
- netcore 內網部署https自簽名證書NetCore內網HTTP
- 怎麼給網站配置SSL證書(https)網站HTTP
- nginx配置SSL證書實現https服務NginxHTTP
- 生成https證書HTTP
- springBoot專案部署整合阿里雲https證書報錯Spring Boot阿里HTTP
- Springboot整合外部Tomcat配置Spring BootTomcat
- SpringBoot中配置外部TomcatSpring BootTomcat
- SpringBoot 之配置外部TomcatSpring BootTomcat
- CDN加速域名https中級CA證書的配置HTTP
- Android okhttp3.0配置https的自簽證書和信任所有證書AndroidHTTP
- 免費https證書HTTP
- 申請免費https證書及nginx相關配置HTTPNginx
- 使用 Lets-encrypt 為 Tomcat 配置 httpsTomcatHTTP
- SpringBoot服務間使用自簽名證書實現https雙向認證Spring BootHTTP
- SSL證書生成,完成HTTPS驗證HTTP
- Tomcat安裝SSL證書Tomcat
- Fiddler安裝https證書HTTP
- 建立並使用https證書HTTP
- 重新生成https證書HTTP
- 亞馬遜雲伺服器aws配置ssl https證書亞馬遜伺服器HTTP
- docker安裝nextcloud私人網盤,開啟https配置證書DockerCloudHTTP
- springboot部署到阿里雲,配置https,springboot專案同時支援http和https請求,阿里雲配置httpsSpring Boot阿里HTTP
- 配置springboot專案使用外部tomcatSpring BootTomcat
- SpringBoot配置外部Tomcat並支援JSPSpring BootTomcatJS
- Amazon EC2 + Tomcat + Ngnix + Godaddy 配置HTTPSTomcatGoHTTP
- tomcat8配置https協議訪問TomcatHTTP協議
- curl 設定https 不驗證證書HTTP
- phpstudy apache 配置 https 證照PHPApacheHTTP
- 自簽名證書 nginx tomcatNginxTomcat