1.申請ssl證書
2.下載ssl證書 打開此網址 https://myssl.com/cert_convert.html 將證書文件(xxx.com.crt)和密鑰文件上傳(xxx.com.key) 輸入密碼后會得到一個jks的文件。上傳到你的tomcat的conf文件夾下即可。
3.修改server.xml
這是tomcat原樣字段 <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> 修改為下面這樣的 <Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" />
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" /> --> //上面這部分是server.xml中原樣的字段 <Connector port="443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" keystoreFile="conf/xxxxxx.com.jks" //這里是你的jks的路徑如果你是放在conf下 修改文件名即可。 keystorePass="123456" //這是你在前面網站上設定的密碼 clientAuth="false" sslProtocol="TLS" />
4.修改web.xml
在web.xml最后粘貼這段代碼。位置在<welcome-file-list>節點下面
<!-- SSL證書配置添加如下 --> <login-config> <!-- Authorization setting for SSL --> <auth-method>CLIENT-CERT</auth-method> <realm-name>Client Cert Users-only Area</realm-name> </login-config> <security-constraint> <!-- Authorization setting for SSL --> <web-resource-collection> <web-resource-name>SSL</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint>
5.重啟tomcat,是重啟!!!!!!!!!!!!!
6.如果還是不可以,檢查自己是否安裝了ssl相關的模塊。