2016-04-03 84 views
0

我的問題:Tomcat的8緩存靜態文件allthough配置,否則

當我訪問靜態文件從comcat 8通過HTTP文件的內容sidely緩存服務器。 我可以排除以下錯誤的:

  1. 這不是我的瀏覽器緩存(禁用,嘗試了不同的瀏覽器,使用了wget上CLI)。 Tomcat返回http 200 OK
  2. 這是not an configuration issue with a conflicting antiResourceLocking
  3. 我不認爲這是一個配置問題? (見下文)

這裏是我的server.xml(我知道這是不是很好把上下文在這裏..)

<Server port="8005" shutdown="SHUTDOWN"> 
    <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> 
    <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 
    <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> 
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 
    <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> 

    <GlobalNamingResources> 

    <Resource name="UserDatabase" auth="Container" 
       type="org.apache.catalina.UserDatabase" 
       description="User database that can be updated and saved" 
       factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 
       pathname="conf/tomcat-users.xml" /> 
    </GlobalNamingResources> 


    <Service name="Catalina"> 

    <Connector port="8888" protocol="HTTP/1.1" 
       connectionTimeout="20000" 
       redirectPort="8443" /> 

     <!-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 --> 
     <Connector 
      protocol="org.apache.coyote.http11.Http11NioProtocol" 
      port="8883" maxThreads="200" 
      socketBuffer="-1" 
      scheme="https" secure="true" SSLEnabled="true" 
      keystoreFile="/vagrant/provision/configFiles/keystore" keystorePass="changeit" 
      clientAuth="false" sslProtocol="TLS"/> 

    <Engine name="Catalina" defaultHost="localhost"> 

     <Realm className="org.apache.catalina.realm.LockOutRealm"> 
     <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
       resourceName="UserDatabase"/> 
     </Realm> 

      <Host name="www.xxx.de" appBase="webapps"> 
         <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" /> 
         <Context path="" docBase="/vagrant/webroot/xxx"> 
          <Resources cachingAllowed="false" /> 
         </Context> 
         <Context path="/r2d2" docBase="/vagrant/webroot/r2d2"/> 
         <Context path="/data" docBase="/vagrant/webroot/shares/data"/> 
      </Host> 

    </Engine> 
    </Service> 
</Server> 

,這是我的context.xml

<Context> 
    <Resources cachingAllowed="false" /> 

    <WatchedResource>WEB-INF/web.xml</WatchedResource> 
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource> 

</Context> 

上下文xml資源標籤僅用於偏執狂。沒有context.xml中的資源標籤,server.xml資源標籤應該足夠了嗎? 但是,這裏是我觀察到的:

當我更改webroot中的文件時,tomcat相應地更改內容長度(!)。所以它實際上檢測到文件已更改。但內容仍然是錯誤的(在文件末尾添加NUL字符,當我在文件系統中放入更多內容時)。我總是得到200好的迴應。 它確實適用於小文件,但不適用於「大」文件,例如〜> 45172字節

我的webapps和工作文件夾爲空(!)。

即使我重新啓動tomcat,該文件仍然是緩存服務器端..這是我失去了我的想法:從哪裏獲取舊的文件內容?我甚至從tomcat讀取了github上的源代碼,並且我已經看到緩存文件的內容存儲在內存中。我對部分緩存文件進行了grep,並且什麼都沒找到。

欲瞭解更多信息:tomcat運行在流浪漢中,但是如果我修改客戶端或主機上的文件並不重要。從文件系統(guest和主機)更改文件,tomcat響應爲200,但傳遞了錯誤的內容。

tomcat-8.0.28正在運行。

沒有更多的想法,留下:(預先感謝您。 菲利普

回答

1

檢查站點與工具,並查找頭。我猜你的問題是,Tomcat是發出錯誤httpheaders你。

每默認的Tomcat發送的每個HTTPS與httpheaders編譯要求:。沒有高速緩存剛剛嘗試用HTTPS請求相同的,如果你看到文件的更改,那麼你可以在你的web.xml中添加以下代碼片段

<filter> 
    <filter-name>ExpiresFilter</filter-name> 
    <filter-class>org.apache.catalina.filters.ExpiresFilter</filter-class> 
    <init-param> 
     <param-name>ExpiresByType image</param-name> 
     <param-value>access plus 0 minutes</param-value> 
    </init-param> 
    <init-param> 
     <param-name>ExpiresByType text/css</param-name> 
     <param-value>access plus 0 minutes</param-value> 
    </init-param> 
    <init-param> 
     <param-name>ExpiresByType application/javascript</param-name> 
     <param-value>access plus 0 minutes</param-value> 
    </init-param> 
</filter> 

我希望它w orks

+0

不要忘記'''' –