首頁  >  問答  >  主體

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

···
就開始重定向死迴圈了

怪我咯怪我咯2701 天前1249

全部回覆(1)我來回復

  • 黄舟

    黄舟2017-05-27 17:47:07

    不需要反向代理,在你要HTTPS的網站web.xml裡加上設定。例如

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

    回覆
    0
  • 取消回覆