http和https支持

请求方式支持http和https:

1.生成证书

  keytool -genkey -alias tomcat -keyalg RSA -keystore E:\kaifa\apache-tomcat-6.0.35\tomcat.keystore -validity 36500

  其中-validity 36500表示证书有效期,100年,默认是90天;-keystore E:\kaifa\apache-tomcat-6.0.35\tomcat.keystore表示存放证书的路径

  将上面的命令在cmd中执行,姓氏和名字特别重要(访问的域名,一般输入ip),记下密码,其他的随意输入,

  --遇到的问题:生成证书时若是姓氏和名字输入错误,删除证书就可以了,

2.配置server.xml

  将配置文件中的<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"   maxThreads="150" scheme="https" secure="true"  clientAuth="false" sslProtocol="TLS" />注释去掉,更改为

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true"  clientAuth="false" keystoreFile="E:\kaifa\apache-tomcat-6.0.35\tomcat.keystore" 
keystorePass="123456" sslProtocol="TLS" useBodyEncodingForURI="true" URIEncoding="utf-8"/>

其中keystoreFile="E:\kaifa\apache-tomcat-6.0.35\tomcat.keystore" 表示文件存放路径,keystorePass="123456"表示证书的密码

--遇到的问题:配置完成后报错 Socket bind failed: [730048] ?????????×???(Э?é/???????/???)????í?? 试了网上说的吧8443的进程杀掉,但是发现你每次重启后还是这个错误,https://blog.csdn.net/gane_cheng/article/details/53001846在这篇博客中找到解决方法  <!--<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />-->将这一行注释掉

3.配置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://     http://127.0.0.1:8101/inte -->https://127.0.0.1:8443/inte

若是要省略端口则配置http访问端口为80,https访问端口为443,访问http:127.0.0.1/inte自动跳转到https://127.0.0.1/inte

猜你喜欢

转载自www.cnblogs.com/hqsbrx/p/9453724.html