服務近2000家企業(yè),依托一系列實踐中打磨過的技術和產(chǎn)品,根據(jù)企業(yè)的具體業(yè)務問題和需求,針對性的提供各行業(yè)大數(shù)據(jù)解決方案。
WEB應用集成HTTPS(http+ssl)讓您能的應用更安全
來源:未知 時間:2018-59-27 瀏覽次數(shù):107次
HTTPS協(xié)議的WEB應用的信息更加安全,同時可降低網(wǎng)站被劫持的風險,HTTPS是以安全為目標的HTTP通道,簡單講是HTTP的安全版。即HTTP下加入SSL層,HTTPS的安全基礎是SSL,HTTPS默認端口是443,而HTTP默認端口為80,本文講解主流http服務配置使支持HTTPS協(xié)議一 、HTTPS安全證書的獲取
- 自己生成:有jdk-tool等工具可以自己生成證書,但不被瀏覽器認可反而會提示不安全問題
- 通過免費渠道獲取:一般大多數(shù)云主機提供商(如阿里云,騰訊云,百度云)都會提供免費證書的生成,但支持的功能和安全性相對較低
- 收費證書:通過www認可的證書提供渠道生成收費證書,安全性較高,兼容性較好
- 1. /usr/local/nginx/sbin/nginx -V 查看nginx版本與編譯安裝了哪些模塊
nginx version: nginx/1.10.3
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments:
- 2. 下載nginx 1.10.3, 并且configure
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
- 3. 執(zhí)行make ,千萬不要make install 否則會覆蓋現(xiàn)有的nginx
- 4. 關閉nginx
- 5. copy ~/download/nginx-1.10.3/objs/nginx 到現(xiàn)有的/usr/local/nginx/sbin/nginx
- 6. /usr/local/nginx/sbin/nginx -V 查看編譯安裝的模塊
nginx version: nginx/1.10.3
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
- 7. 修改nginx.conf文件
server {
server_name xxx.yyy.com;
listen 443;
ssl on;
ssl_certificate /usr/local/nginx/conf/xxx.com_server.txt; #公鑰
ssl_certificate_key /usr/local/nginx/conf/xxx.com_private.txt; #私鑰
location / {
# location的一堆配置
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
###########################80端口的處理###############################
server {
listen 80;
server_name xxx.yyy.com;
send_timeout 1800;
rewrite ^(.*)$ https://xxx.yyy.com$1 permanent; # 80端口跳轉(zhuǎn)
}
注:如果是nginx全新安裝只需選擇ssl模塊配置即可
三、TOMCAT配置SSL使支持HTTPS訪問
注:如果是nginx全新安裝只需選擇ssl模塊配置即可
三、TOMCAT配置SSL使支持HTTPS訪問
- 配置Tomcat證書配置: 打開 Tomcat 配置文件 confserver.xml。取消注釋,并添加兩個屬性 keystoreFile,keystorePass。
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" keystoreFile="E:/tomcat.keystore" keystorePass="123456" />
其中,keystoreFile是生成的證書文件地址,keystorePass是密鑰庫口令。
- 測試HTTPS:測試鏈接 http://www.jxqxj.com/,觀察Tomcat輸出日志會發(fā)現(xiàn)異常。
嚴重: Failed to initialize end point associated with ProtocolHandler ["http-apr-8443"]
java.lang.Exception: Connector attribute SSLCertificateFile must be defined when using SSL with APR
at org.apache.tomcat.util.net.AprEndpoint.bind(AprEndpoint.java:484)
at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:566)
at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:417)
at org.apache.catalina.connector.Connector.initInternal(Connector.java:956)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
解決方法是注釋confserver.xml文件中下面一行。
<!--<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />-->
重啟Tomcat ,這時可以看到瀏覽器已經(jīng)可以打開 HTTPS 鏈接了。
以上以tomcat,nginx等主流http服務為例介紹了配置HTTPS以及安全證書獲取的詳細步驟,任何安全協(xié)議都不是絕對安全,安全是相對的,配置HTTPS只是增加了應用的安全級別,其他防護任然不可或缺
以上以tomcat,nginx等主流http服務為例介紹了配置HTTPS以及安全證書獲取的詳細步驟,任何安全協(xié)議都不是絕對安全,安全是相對的,配置HTTPS只是增加了應用的安全級別,其他防護任然不可或缺