`

tomcat 部署 https访问方式

 
阅读更多

 

第一步:打开jdk 安装目录的bin目录,输入命令 按照步骤,生成证书


keytool -genkey -alias tomcat -keyalg RSA -keystore C:\tomcat.keystore

提示输入密码,使用Tomcat的默认值changeit (这个需要注意),然后按照相应的

提示步骤一次进行即可
输入相关信息后确认将生成PCKS1.2格式的数字证书于C:\tomcat.keystore
 
第二步配置tomcat


找到server.xml,找到ssl这一段
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation -->
<!--<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />-->
去掉这段的注释,添加keystoreFile="C:\tomcat.keystore"
keystorePass="changeit "的属性
改动完成后配置为: 可以直接拷贝复制进去即可
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" keystoreFile="C:\tomcat.keystore" keystorePass="changeit " sslProtocol="TLS" />

注意红线部分是你注册时的密码
然后重启tomcat就能使用HTTPS访问


第三步:强制https访问
在tomcat\conf\web.xml中的</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>

 


tomcat例子文件
tomcat 部署 https访问方式 - 寒城飞雪 - zhanwenlongchina

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics