nginx - 多域名下tomcat配置指定域名https并使其强制跳转

查看:443
本文介绍了nginx - 多域名下tomcat配置指定域名https并使其强制跳转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

如何让tomcat在多域名情况下,使其中一个域名强制使用https呢?看网上好多配置,都是在一个域名的情况下进行的。
比如:一个tomcat上有test.emp.com和testadmin.emp.com.现在要让testadmin.emp.com上的内容强制使用https访问。不知该如何配置呢?
使用nginx配置了下433端口,发现testadmin.emp.com确实能使用https访问,但同时还能用http访问。之后在监听的80端口加了条

server {  
  listen      80;  
  server_name    testadmin.emp.com;  
  return      301 https://$server_name$request_uri;  
} 

或者加
···

server{  
    server_name  testadmin.emp.com;;  
    listen 80;  
    index index.jsp;  

    if ($host = ' testadmin.emp.com;' ) {
        rewrite ^(.*)$  https:// testadmin.emp.com;$1 permanent;  
    }
    location / {  
             proxy_pass http://127.0.0.1:8080;  
             proxy_set_header HOST $host;  
             proxy_set_header X-Real-IP $remote_addr;  
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
             proxy_set_header X-Forwarded-Proto $scheme;  
    }  
}

···
就开始重定向死循环了

解决方案

不需要反向代理,在你要HTTPS的站点web.xml里加<security-constraint>配置。例如

<security-constraint>
    <display-name>zzz</display-name>
    <web-resource-collection>
      <web-resource-name>xxx</web-resource-name>
      <url-pattern>/xxx/*</url-pattern>  ##指定需要强制https的url
      <http-method>DELETE</http-method> 
      <http-method>GET</http-method>
      <http-method>POST</http-method>
    </web-resource-collection>
    <user-data-constraint>
      <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
  </security-constraint>
  <context-param>
    <param-name>ca_root</param-name>
    <param-value>/xxx/tomcat.keystore</param-value> ##指定服务器证书ks
  </context-param>

这篇关于nginx - 多域名下tomcat配置指定域名https并使其强制跳转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆