您的位置:首页 > 理论基础 > 计算机网络

tomcat配置https访问系统

2013-10-11 11:33 761 查看
确认系统中装好了openssl,如果没有则安装!

通过https协议访问,需要安装证书!这里使用java去生成证书:cmd,命令行执行命令:

keytool -v -genkey -alias tomcat -keyalg RSA -keystore /weblogic/apache-tomcat-6.0.32/conf/tomcat.keystore


keytool -v -genkey -alias tomcat -keyalg RSA -keystore D:\tomcat.keystore
输入密码和确认密码,再输入相关信息。这里把证书生成到了。/weblogic/apache-tomcat-6.0.32/conf/tomcat.keystore目录下,如果是windows,则是D:\tomcat.keystore目录。

打开tomcat目录conf下的server.xml,8080端口的redirectPort指向443,或者8443,443为ssl协议默认的端口。

<Connector port="8080" protocol="HTTP/1.1"
maxThreads="150" connectionTimeout="20000"
redirectPort="443" />

<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation -->

<!--keystoreFile就是java生成的证书文件,我放在了tomcat的conf目录下,keystorePass就是生成证书时输入的密码-->
<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" keystoreFile="conf/server.keystore" keystorePass="zyujiePass"/>

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="443" />
上述配置完成了,输入https://127.0.0.1:443/可以访问了。不过443是https默认的端口,我们只用https://127.0.0.1/即可。

在tomcat下面conf的目录:web.xml最后添加下面配置。这样我们访问webapp下面的系统,都会转发成https了。

<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>
http://127.0.0.1:8080/xxx/login.jsp 会被转发成 https://127.0.0.1/xxx/login.jsp
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: