2016-02-05 176 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" /> 

固定的东西,对我们来说。