前幾天客戶提出要強制使用HTTPS方式訪問Tomcat中的相關項目,于是研究了下,現將具體的步驟寫下:
主要分2步:讓tomcat能使用https--->強制使用https訪問
1.讓tomcat能使用https
A.在運行命令JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg
RSA -keystore C:\Tomcat\GMAE3.0Tomcat\tomcat.keystore
這樣就生成了證書,將證書放到合適的地方(任意地方都可以)
B.打開tomcat目錄下的server.xml文件并找到關于ssl的相關段
C.去掉注釋,添keystoreFile="C:\Tomcat\GMAE3.0Tomcat\tomcat.keystore" keystorePass="tomcat"的屬性改動完成后配置為:
D.然后重啟tomcat就能使用HTTPS訪問
2.強制https訪問
在tomcat\conf\web.xml中的</welcome-file-list>后面,加上這樣一段:
完成以上步驟后,在瀏覽器中輸入http的訪問地址也會自動轉換為https了
主要分2步:讓tomcat能使用https--->強制使用https訪問
1.讓tomcat能使用https
A.在運行命令JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg
RSA -keystore C:\Tomcat\GMAE3.0Tomcat\tomcat.keystore
這樣就生成了證書,將證書放到合適的地方(任意地方都可以)
B.打開tomcat目錄下的server.xml文件并找到關于ssl的相關段
1
<!-- Define a SSL HTTP/1.1 Connector on port 8443
2
This connector uses the JSSE configuration, when using APR, the
3
connector should be using the OpenSSL style configuration
4
described in the APR documentation -->
5
<!--<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
6
maxThreads="150" scheme="https" secure="true"
7
clientAuth="false" sslProtocol="TLS" />-->
8

2

3

4

5

6

7

8

C.去掉注釋,添keystoreFile="C:\Tomcat\GMAE3.0Tomcat\tomcat.keystore" keystorePass="tomcat"的屬性改動完成后配置為:
1
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" keystoreFile="C:\Tomcat\GMAE3.0Tomcat\tomcat.keystore" keystorePass="tomcat" sslProtocol="TLS" />
2

2

D.然后重啟tomcat就能使用HTTPS訪問
2.強制https訪問
在tomcat\conf\web.xml中的</welcome-file-list>后面,加上這樣一段:
1
<login-config>
2
<!-- Authorization setting for SSL -->
3
<auth-method>CLIENT-CERT</auth-method>
4
<realm-name>Client Cert Users-only Area</realm-name>
5
</login-config>
6
<security-constraint>
7
<!-- Authorization setting for SSL -->
8
<web-resource-collection >
9
<web-resource-name >SSL</web-resource-name>
10
<url-pattern>/*</url-pattern>
11
</web-resource-collection>
12
<user-data-constraint>
13
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
14
</user-data-constraint>
15
</security-constraint>
16

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

完成以上步驟后,在瀏覽器中輸入http的訪問地址也會自動轉換為https了