1、使用keytool来生成tomcat的证书
keytool -genkeypair -alias 'tomcat' -keyalg 'RSA' -keystore '路径'
2、server.xml 增加此内容
<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="/home/lighthouse/tomcat/apache-tomcat-8.5.88/conf/tomcat.keystore"
keystorePass="密码" />
3、进入tomcat安装目录 再进入bin 解压 tomcat-native.tar.gz 进入解压目录中的native目录
4、配置JDK目录 export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
5、执行 ./configure --with-apr=/usr/bin/apr-1-config --with-ssl=yes
make
sudo make install
6、库生成在 /usr/local/apr/lib目录下就是成功了
7、把库赋值到环境变量的目录中cp /usr/local/apr/lib/libtcnative* /usr/lib/
8、启动tomcat 查看是否占用 443端口
9、 在conf目录下的web.xml最下面添加(可以强制重定向443端口到https)
<login-config>
<auth-method>CLIENT-CERT</auth-method>
<realm-name>Client Cert Users-only Area</realm-name>
</login-config>
<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>