tomcat配置https访问系统

确认系统中装好了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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值