Loading... 1.进入到linux目录下 ```html has-numbering /usr/local/tomcat7/conf/ ``` 2.生成证书 ```html has-numbering keytool -genkey -alias tomcat -keyalg RSA -keystore /usr/local/tomcat7/conf/.keystore ``` ```html has-numbering cat conf/.keystore ``` keytool -genkey:自动使用默认的算法生成[公钥](https://so.csdn.net/so/search?q=%E5%85%AC%E9%92%A5&spm=1001.2101.3001.7020)和私钥 -alias[名称]:给证书取个别名 -keyalg:制定密钥的算法,如果需要制定密钥的长度,可以再加上keysize参数,密钥长度默认为1024位,使用DSA算法时,密钥长度必须在512到1024之间,并且是64的整数倍 -keystore:参数可以指定密钥库的名称。密钥库其实是存放迷药和证书文件,密钥库对应的文件如果不存在会自动创建。 -validity:证书的有效日期,默认是90天 -keypass changeit:不添加证书密码 -storepass changeit:不添加存储证书的密码 3.修改tomcat配置文件server.xml 修改配置tomcat服务器 server.xml ``` <Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" uRIEncoding="UTF-8" />12345 ``` 将8443 改成443 ,因为https默认的端口是443,http默认的80 释放以下,将8443改成443,保持对称 keystoreFile 和 keystorePass 添加上 ``` <Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="D:/software/apache-tomcat-7.0.54/tomcat.keystore" keystorePass="Ab123456" /> 12345 ``` 4.重启tomcat 只运行 https,不允许http 则 web.xml 的 welcome-file-list 下面 中添加 ``` <welcome-file-list> <welcome-file>/</welcome-file> </welcome-file-list> <security-constraint> <web-resource-collection> <web-resource-name>sslwebsokect</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint>123456789101112 ``` 6.再次重启tomcat,访问http后会自动跳转到https 5.浏览器访问https 问题解决: 在两个不同的机器上,使用相同的.keystore,配置也相同,但是其中一个机器不知道为何总是访问不了https 检查步骤: 1.用wget连本地 ![](https://img-blog.csdn.net/20160906180736795) 2.用wget连外网 ![](https://img-blog.csdn.net/20160906180742454) 3.用lsof -i:8443检查端口的监听状态 ![](https://img-blog.csdn.net/20160906180746842) ![](https://img-blog.csdn.net/20160906180750639) 4.用/etc/init.d/iptables status检查防火墙状态 ![](https://img-blog.csdn.net/20160906180754110) ![](https://img-blog.csdn.net/20160906180757827) 5.发现问题:没有进行端口的转发,执行以下命令即可 ```html has-numbering iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 8443 ``` 6.解决ie访问不了的问题 ```plain has-numbering clientAuth="false" sslProtocol="TLS" ciphers="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA" 1 ``` ![](https://img-blog.csdn.net/20160930155832796) 最后修改:2022 年 03 月 15 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 0 如果觉得我的文章对你有用,请随意赞赏