1
.生成keystore
利用 JDK
自带的 keytool
工具完成keystore
的生成,运行命令:
[JAVA_HOME]/bin/keytool -genkey -alias tomcat
-keyalg RSA -keystore [location/fileName]
根据提示输入各项值。最后在location
路径下生成名为fileName
的KeyStore
文件。
2.
修改server.xml
在tomcat
的conf
目录下找到server.xml,
在该文件中找到与SSL
相关的内容,<!-- Define a SSL HTTP/1.1
Connector on port 8443 -->
,将“<Connector
port="8443"……
”这个标签的注释去掉,并且在加入两个属性:keystoreFile
和keystorePass
,其中keystoreFile
指向上一步生成的KeyStore
文件,keytStorePass
为上一步中输入的keystore
密码。
3.
强制Https
访问
经过上面两部的设置,Tomcat
已经可以支持Https
的访问了,但是Http
的访问也同样支持。
在tomcat
的conf
目录下找到web.xml
文件,加入如下配置:
<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>
保存文件,现在再启动Tomcat
如果输入的是Http
的地址会自动跳转到Https
的地址。
|