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

Centos里的tomcat开启https接口

2017-09-12 14:17 225 查看

1.静默安装tomcat

yum install tomcat


2.安装tomcat的web管理包

yum install tomcat-webapps tomcat-admin-webapps


3.生成证书 (将 localhost 换成 ip)

keytool -genkey -v -alias tomcat -keyalg RSA -validity 3650 -keystore tomcat.keystore -dname "CN=localhost,OU=cn,O=cn,L=cn,ST=cn,c=cn" -storepass 123456 -keypass 123456


4.修改 tomcat 配置

cd /usr/share/tomcat/conf


vi server.xml


增加如下内容 (其实 server.xml里面已经有,不过被注释了)

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="/usr/share/tomcat/conf/tomcat.keystore" keystorePass="123456"
truststoreFile="/usr/share/tomcat/conf/tomcat.keystore" truststorePass="123456"/>


5.将证书变为可以在 windows 环境下安装的 cre文件

keytool -export -alias tomcat -file file.cer -keystore  tomcat.keystore -validity 36500


6.然后将证书拷贝到 windows桌面.



7.双击安装 file.cer文件

8.配置http重定向到https

在 /usr/share/tomcat/conf/web.xml中加入

<security-constraint>

<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>


9.使用命令 service tomcat start 命令启动.

10.打开 IE浏览器,输入 https://ip 访问

.弹出的阻止页面选择不安全继续浏览.

题外话: http默认端口是80,https默认端口是443.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  tomcat centos