Centos下配置tomcat7的https证书

时间:2023-03-08 18:32:41

近期搞定了HTTPS配置,特此记录。

1、把下载的文件拷贝到cert文件夹,然后放在tomcat根目录下(与conf同一级目录)。
2、配置conf下的server.xml,修改下面3个节点,如下:

<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" />
<Connector port="443" protocol="HTTP/1.1"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
keystoreFile="cert/your-name.pfx"
keystoreType="PKCS12"
keystorePass="you-password"
clientAuth="false" sslProtocol="TLS" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="443" />

3、配置conf下的web.xml,让http自动跳转https。在</web-app>前加入下面配置即可。

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

4、在服务器上重启tomcat的,访问你的网站。