2011-06-25 19 views
9

我在Jetty 6的前面使用反向代理(Apache)。用戶使用SSL連接到Apache,並且Apache通過普通的HTTP將一些請求轉發到Jetty。我希望Jetty使用安全會話cookie。Jetty安全會話cookie在使用HTTP的反向代理的背後

有人會認爲這將是任何人在安裝Jetty後第一件事 - 但我很難讓它工作。

我設置了Jetty以使用安全Cookie,如another stackoverflow question中所述。但是,Jetty拒絕使用安全Cookie - 我認爲這是因爲來自反向代理的連接不是SSL。

我試圖說服Jetty,它正在處理通過SSL發出的請求,並在sonatype.com處進行了說明。也就是說,我加入Apache的以下內容:

RequestHeader set X-Forwarded-Scheme "https" 

和/etc/jetty/jetty.xml:

<Set name="handler"> 
    <New id="Handlers" class="org.mortbay.jetty.handler.rewrite.RewriteHandler"> 
    <Set name="rules"> 
     <Array type="org.mortbay.jetty.handler.rewrite.Rule"> 
     <Item> 
      <New id="forwardedHttps" 
       class="org.mortbay.jetty.handler.rewrite.ForwardedSchemeHeaderRule"> 
      <Set name="header">X-Forwarded-Scheme</Set> 
      <Set name="headerValue">https</Set> 
      <Set name="scheme">https</Set> 
      </New> 
     </Item> 
     </Array> 
    </Set> 

    <Set name="handler"> 
     <New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection"> 
     <Set name="handlers"> 
      <Array type="org.mortbay.jetty.Handler"> 
      <Item> 
       <New id="Contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection"/> 
      </Item> 
      <Item> 
       <New id="DefaultHandler" class="org.mortbay.jetty.handler.DefaultHandler"/> 
      </Item> 
      <Item> 
       <New id="RequestLog" class="org.mortbay.jetty.handler.RequestLogHandler"/> 
      </Item> 
      </Array> 
     </Set> 
     </New> 
    </Set> 
    </New> 
</Set> 

仍然沒有安全cookie。有什麼建議麼?

回答

5

我不能得到這個與Jetty 6工作。升級到Jetty 9後,我得到了它的工作。

我在/etc/jetty.xml中對此進行了更改。有人評論了,我註釋掉它:

<!-- Uncomment to enable handling of X-Forwarded- style headers --> 
<Call name="addCustomizer"> 
    <Arg><New class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg> 
</Call> 

在反向代理(現在nginx的)proxy_set_header X轉發 - 協議是用來告訴碼頭請求是HTTP或HTTPS:

location/{ 
    proxy_pass http://127.0.0.1:8080; 
    proxy_pass_header Server; 
    proxy_set_header Host $http_host; 
    proxy_set_header X-Forwarded-Proto $scheme; 
} 

最後,在webapp的web.xml中,這將啓用安全和http專用會話cookie:

<?xml version="1.0" encoding="UTF-8"?> 

<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
     version="3.0"> 

    <!-- filters and other stuff here --> 

    <session-config> 
    <session-timeout>120</session-timeout> 
    <cookie-config> 
     <http-only>true</http-only> 
     <secure>true</secure> 
    </cookie-config> 
    <tracking-mode>COOKIE</tracking-mode> 
    </session-config> 

</web-app>