2016-02-05 84 views
0

我有一個在Tomcat 7中運行的Spring Web MVC應用程序,在Tomcat前面有nginx 1.1.19。nginx'干擾'緩存響應?

我已經啓用Cache-Control:max-age=31536000, must-revalidate與Spring Security和頭很好回到瀏覽器。

如果我直接運行應用程序到Tomcat一切正常,靜態資源全部用304

通過nginx的運行回報一些靜態的資源返回304,有的回報200,所有表現出正確的格式Cache-Control頭。我無法找到什麼模式和什麼是不緩存的。

nginx的confix很簡單:

location /TSAdmin { 
     proxy_pass http://localhost:8030; 
     proxy_redirect http://localhost:8030 https://10.10.5.63; 
} 

任何想法,將不勝感激。

+0

您能提供緩存的資源(例如有304個響應代碼)和不是(例如有200個響應代碼)的資源的完整響應(包括標題)嗎? – Castaglia

+0

對不起,我應該關閉這個。結果這是Spring頭配置問題。如果你喜歡,我可以分享我的Spring Security配置。 –

回答

1

這翻出的是一個Spring Security的配置問題,這兩個片段解決了這個問題:

<http> 
     <headers> 
     <cache-control disabled="true" /> 
     </headers> 
     <intercept-url pattern="/css/**" access="permitAll" /> 
     <intercept-url pattern="/frameworks/**" access="permitAll" /> 
     <intercept-url pattern="/img/**" access="permitAll" /> 
     <intercept-url pattern="/js/**" access="permitAll" /> 
     <intercept-url pattern="/fonts/**" access="permitAll" /> 
     <intercept-url pattern="/images/**" access="permitAll" /> 
    </http> 

<mvc:resources location="/, /css/" mapping="/css/**" cache-period="31536000" /> 
    <mvc:resources location="/, /frameworks/" mapping="/frameworks/**" cache-period="31536000" /> 
    <mvc:resources location="/, /img/" mapping="/img/**" cache-period="31536000" /> 
    <mvc:resources location="/, /js/" mapping="/js/**" cache-period="31536000" /> 
    <mvc:resources location="/, /fonts/" mapping="/fonts/**" cache-period="31536000" /> 
    <mvc:resources location="/, /images/" mapping="/images/**" cache-period="31536000" /> 

固定的東西,對我們來說。