柚子快報邀請碼778899分享:HTTPS:HTTP +SSL
柚子快報邀請碼778899分享:HTTPS:HTTP +SSL
HTTPS是以安全為目標的 HTTP 通道,在HTTP的基礎上通過傳輸加密和身份認證保證了傳輸過程的安全性。
HTTPS 在HTTP 的基礎下加入SSL?層,HTTPS 的安全基礎是 SSL,因此加密的詳細內容就需要 SSL。
http是超文本傳輸協(xié)議,信息是明文傳輸?shù)模╤ttp協(xié)議是不安全的,黑客可以在用戶和服務器之間設置攔截器竊取傳輸?shù)膬热?。也可以偽造用戶提交的表單向服務器發(fā)出請求,從而獲取到服務器的響應)。https則是具有安全性的ssl加密傳輸協(xié)議,http和https使用的是完全不同的連接方式,用的端口也不一樣,前者是80,后者是443。
spring boot項目配置SSL證書,需要準備域名,ssl證書,將域名解析到自己的服務器,然后通過域名申請證書,再下載適配自己項目的證書文件,通過配置文件進行相應配置,就可以進行https訪問了
證書生成放在項目根目錄
cd C:\Java\jdk-1.8\bin
keytool -genkey -alias tomcat -keyalg RSA -keystore d:/https.keystore
http:
port: 80
server:
port: 443
ssl:
key-store: https.keystore
key-alias: tomcat
enabled: true
key-store-password: 123456
key-store-type: JKS
@Configuration
public class HttpsConfig {
@Value("${server.port}")
private int httpsPort;
@Value("${http.port}")
private int httpPort;
@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(initiateHttpConnector());
return tomcat;
}
private Connector initiateHttpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(httpPort);
connector.setSecure(false);
connector.setRedirectPort(httpsPort);
return connector;
}
}
柚子快報邀請碼778899分享:HTTPS:HTTP +SSL
文章來源
本文內容根據(jù)網(wǎng)絡資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點和立場。
轉載請注明,如有侵權,聯(lián)系刪除。