1.配置Tomcat,打开$CATALINA_HOME/conf/server.xml,修改如下,
<Connector
port="8080" protocol="HTTP/1.1"
修改参数=>
<Connector
port="80" protocol="HTTP/1.1"
<!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
去掉注释且修改参数=>
<Connector
port="443" protocol="HTTP/1.1" SSLEnabled="true"
注释:标识为淡蓝色的两个参数,分别是证书文件的位置和<tomcat>的主密码,在证书文件生成过程中做了设置
<!--
-->
修改参数=>
<Connector
port="8009" enableLookups="false" protocol="AJP/1.3" redirectPort="443" />
2.强制https访问
在tomcat\conf\web.xml中的</welcome-file-list>后面加上这样一段:
<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>
<!-- 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>