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>
本文介绍了如何在Tomcat中配置SSL以启用HTTPS访问。首先,通过修改$CATALINA_HOME/conf/server.xml文件,调整连接器参数,设置证书文件路径和密码。接着,取消注释并配置443端口的SSL连接器。然后,为了强制HTTPS访问,需在tomcatconfweb.xml中添加登录配置和安全约束,确保所有请求都通过安全通道传输。
1万+

被折叠的 条评论
为什么被折叠?



