【问题标题】:nginx 'interfering' with cache response?nginx“干扰”缓存响应?
【发布时间】:2016-05-15 22:18:59
【问题描述】:

我有一个 Spring Web MVC 应用程序在 Tomcat 7 中运行,Tomcat 前面有 nginx 1.1.19。

我已经使用 Spring Security 启用了Cache-Control:max-age=31536000, must-revalidate,并且标头可以很好地返回到浏览器。

如果我将应用程序直接运行到 Tomcat,一切都按预期运行,静态资源全部返回 304。

通过 nginx 运行一些静态资源返回 304,一些返回 200,all 显示格式正确的 Cache-Control 标头。我在缓存和未缓存的内容中找不到任何模式。

nginx 的配置非常简单:

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

任何想法都将不胜感激。

【问题讨论】:

  • 您能否提供缓存的资源(例如具有 304 响应代码)和未缓存的资源(例如具有 200 响应代码)的完整响应(包括标头)?
  • 对不起,我应该关闭这个。这原来是一个 Spring 标头配置问题。如果你愿意,我可以分享我的 Spring Security 配置。

标签: spring tomcat nginx spring-security browser-cache


【解决方案1】:

原来是 Spring Security 配置问题,这两个 sn-ps 解决了这个问题:

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

为我们解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-01
    • 1970-01-01
    相关资源
    最近更新 更多