柚子快報(bào)邀請碼778899分享:HTTPS:HTTP +SSL
柚子快報(bào)邀請碼778899分享:HTTPS:HTTP +SSL
HTTPS是以安全為目標(biāo)的 HTTP 通道,在HTTP的基礎(chǔ)上通過傳輸加密和身份認(rèn)證保證了傳輸過程的安全性。
HTTPS 在HTTP 的基礎(chǔ)下加入SSL?層,HTTPS 的安全基礎(chǔ)是 SSL,因此加密的詳細(xì)內(nèi)容就需要 SSL。
http是超文本傳輸協(xié)議,信息是明文傳輸?shù)模╤ttp協(xié)議是不安全的,黑客可以在用戶和服務(wù)器之間設(shè)置攔截器竊取傳輸?shù)膬?nèi)容。也可以偽造用戶提交的表單向服務(wù)器發(fā)出請求,從而獲取到服務(wù)器的響應(yīng))。https則是具有安全性的ssl加密傳輸協(xié)議,http和https使用的是完全不同的連接方式,用的端口也不一樣,前者是80,后者是443。
spring boot項(xiàng)目配置SSL證書,需要準(zhǔn)備域名,ssl證書,將域名解析到自己的服務(wù)器,然后通過域名申請證書,再下載適配自己項(xiàng)目的證書文件,通過配置文件進(jìn)行相應(yīng)配置,就可以進(jìn)行https訪問了
證書生成放在項(xiàng)目根目錄
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;
}
}
柚子快報(bào)邀請碼778899分享:HTTPS:HTTP +SSL
文章來源
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場。
轉(zhuǎn)載請注明,如有侵權(quán),聯(lián)系刪除。