1.静默安装tomcat
yum install tomcat
2.安装tomcat的web管理包
yum install tomcat@H_301_10@-webapps tomcat@H_301_10@-admin@H_301_10@-webapps
3.生成证书 (将 localhost 换成 ip)
keytool @H_301_10@-genkey @H_301_10@-v @H_301_10@-alias tomcat @H_301_10@-keyalg RSA @H_301_10@-validity 3650 @H_301_10@-keystore tomcat.keystore @H_301_10@-dname "CN=localhost,OU=cn,O=cn,L=cn,ST=cn,c=cn" @H_301_10@-storepass 123456 @H_301_10@-keypass 123456
4.修改 tomcat 配置
cd /usr/share/tomcat/conf
vi server.xml
增加如下内容 (其实 server.xml里面已经有,不过被注释了)
<Connector @H_301_10@port="8443" @H_301_10@protocol="org.apache.coyote.http11.Http11NioProtocol" @H_301_10@maxThreads="150" @H_301_10@SSLEnabled="true" @H_301_10@scheme="https" @H_301_10@secure="true" @H_301_10@clientAuth="false" @H_301_10@sslProtocol="TLS" @H_301_10@keystoreFile="/usr/share/tomcat/conf/tomcat.keystore" @H_301_10@keystorePass="123456" @H_301_10@truststoreFile="/usr/share/tomcat/conf/tomcat.keystore" @H_301_10@truststorePass="123456"/>
5.将证书变为可以在 windows 环境下安装的 cre文件
keytool @H_301_10@-export @H_301_10@-alias tomcat @H_301_10@-file file.cer @H_301_10@-keystore tomcat.keystore @H_301_10@-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.