Tomcat Https Support

Tomcat支持Https

1. 生成keystore文件。

$ keytool -genkey -alias tomcat -keyalg RSA
过程中需要设置keystore和key密码,假设为tomcatpassword。

该命令将在当前目录生成.keystore文件,假设为/home/user/.keystore。

2. 修改tomcat配置中ssl相关设置。

<!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
    maxThreads="150" scheme="https" secure="true"
    clientAuth="false" sslProtocol="TLS" />
-->
添加keystoreFile="/home/usr/.keystore" keystorePass="tomcatpassword"

P.S. 网上看有帖子说还要修改protocol:protocol="org.apache.coyote.http11.Http11Protocol",不知是何用意,暂且在此记录。

3. 重启tomcat。浏览器访问https://localhost:8443。因为浏览器没有相应的证书,所以会提示不安全的访问。选择继续访问即可。

配置应用使用https访问(未测试)

在应用的web.xml添加

<security-constraint>
    <web-resource-collection>
        <web-resource-name>securedapp</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

  将CONFIDENTIAL修改为NONE,可不用https。

猜你喜欢

转载自runningeagle.iteye.com/blog/1837369