阿里云服务器Tomcat9服务器配置通过https协议访问。
环境信息:
阿里云centos7.6 、 Tomcat9 、SSL证书(是在阿里云官网免费申请的)
具体配置步骤:
1,在申请到阿里云的免费DV证书后,下载 "证书 for Tomcat",阿里云证书安装配置说明
文件说明:
****.pfx文件ssl证书,pfx-password.txt 文件中保存证书密码。
2,在Tomcat更目下建个cert文件夹,把下载的证书文件放里面。
3,找到安装Tomcat目录下该文件server.xml,一般默认路径都是在 conf 文件夹中。找到 <Connection port="8443" 标签,默 认是注释的,去掉注释,修改增加内容【红色部分为修改部分】
<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true"> <SSLHostConfig> <Certificate certificateKeystoreFile="/opt/software/apache-tomcat-9.0.27/cert/3145101_www.freeshine.top.pfx" certificateKeystoreType="PKCS12" certificateKeystorePassword="123456" type="RSA" /> </SSLHostConfig> </Connector> |
注意事项:
访问端口有8443修改成443。
protocol属性值有org.apache.coyote.http11.Http11AprProtocol 修改成 org.apache.coyote.http11.Http11NioProtocol
4,修改Tomcat9配置的web.xml
编辑web.xml,不加下面这段的话不能把http请求转为https
在该文件</welcome-file-list>标签(一般在文件最末尾)后面加上这样一段
<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> |
5,重启tomcat9服务器