由于https协议比http协议安全,但是如果网站安装了ssl(如果没有安装,可百度搜索"阿里云ssl免费证书",阿里官网会提供安装方法,比较简单),发现每次输入网址必须得手动输入https,而且大家习惯输入www.网址.com,会直接导致访问不到网站的.下面介绍直接修改tomcat配置,使得访问http(或者直接输入www.网址.com)自动变为访问https://www.网址.com.
1.找到tomcat
的server.xml
,如果里面没有如下代码:
直接添加到上一个<Connector ..... />
标签下面即可,比如下面这段代码:
原文地址:tomcat配置 使得访问http协议(或者直接输入www.网址.com) 直接跳转访问https协议 - 廖强的博客
2.在tomcat
的web.xml
的</welcome-file-list>
后面添加下面的代码,重启tomcat即可成功
<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>