`

tomcat webapp根域名访问和webapp自动限制为https访问

 
阅读更多

一,配置tomcat中的webapp为直接使用本机IP或域名访问

1,打开tomcat\conf\server.xml配置文件

 

2,Engine节点中defaultHost原localhost改为目标域名

 

<Engine name="Catalina" defaultHost="www.xxx.com">

 

3,在Host标签之中加入如下节点内容:

 

<Context path="/app1" docBase="/app1" />  
<Context path="" docBase="/app1" />  


表示:使用根域名或者采用添加app1路径名同样是访问app1项目内容

 

二,htttp地址访问webapp站点时跳转为https访问

如: http://ip/ 访问直接 跳转为 https://ip/访问

1,生成tomcat密钥文件tomcat.keystore,放置在特定目录,如“C:/tomcat/conf/”

2,在tomcat\conf\server.xml配置文件Service节点下添加如下内容:

 

<Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" 
               keystoreFile="C:/tomcat/conf/tomcat.keystore" keystorePass="abcdefgh" />

3,在项目的web.xml中welcome-file-list节点后配置如下内容:

 

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


如果要所有app均使用https则上述内容配置在tomcat的web.xml中

 

重启 tomcat

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics