2008-11-24 42 views
22

我有一個目錄,某個進程上載了一些.pdf文件。這個過程不在我的控制之下。在Tomcat中爲單個目錄配置符號鏈接

我需要使用Tomcat通過網站使這些文件可用。

我有一個目錄/var/lib/tomcat5/webapps/test1可用於網絡,我可以在瀏覽器中看到它的文件。

因此,我創建了一個符號鏈接,指向.pdf文件的目錄: /var/lib/tomcat5/webapps/test1/files/,但我在該目錄中看不到任何內容。

如何才能在test1目錄中啓用符號鏈接?我不想在任何地方啓用符號鏈接,只是爲了使網頁上有.pdf文件的目錄。

回答

46

有與創建一個META-INF/context.xml的包含<Context path="/myapp" allowLinking="true">解決的幾個問題

最大的問題是,如果存在conf/context.xmlallowLinking<Context>那裏需要優先於 a <Context>META-INF/context.xml。如果conf/context.xml中沒有明確定義allowLinking,這與allowLinking="false"的說法相同。 (請參閱my answer以解決上下文優先問題)

要確保您的應用允許鏈接,您必須說<Context override="true" allowLinking="true" ...>

另一個問題是path="/myapp"META-INF/context.xml中被忽略。爲了避免混淆,最好將它排除在外。 <Context>中的唯一時間pathserver.xmlofficial Tomcat docs recommend against<Context> s寫入server.xml中有任何影響。

最後,我建議使用conf/Catalina/localhost/myapp.xml文件,而不是myapp/META-INF/context.xml文件。這種技術意味着你可以保持你的META-INF清潔的內容,這是你的web應用程序的內容 - 我不喜歡冒險在我的web應用程序的內部冒險。 :-)

15

在你的web應用程序中創建一個META-INF目錄中的context.xml文件包含:

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

<Context path="/myapp" allowLinking="true"> 

</Context> 

更多在這裏:http://www.isocra.com/2008/01/following-symbolic-links-in-tomcat/

+0

是的,所有我所要做的就是創建一個context.xml文件: 在/ var/lib中/ TOMCAT5/webapps /下測試1/META -INF/context.xml 該鏈接非常有幫助。謝謝。 – 2008-11-24 19:58:04

+0

謝謝你。任何想法如何配置tomcat(6)始終遵循符號鏈接? – 2008-11-25 21:09:14

1

我是用這種方式做出來的。 我編輯這個其他配置文件:apache-tomcat-7.0.33/conf/服務器。XML主機標籤我說:

<Context path="/data" docBase="C:\datos" debug="0" reloadable="true" crossContext="false"/> 

所以,你可以ACCES通過:http://localhost/data

6

是的,我知道這是一個老問題,但我發現了一個新的解決方案,使用與安裝 - -bind選項,而不是一個符號鏈接,和Tomcat不需要任何重新配置​​:

CD的/ var/lib中/ TOMCAT5/webapps /下測試1/

的mkdir文件

安裝--bind /路徑/到/實際/上傳/目錄/文件的文件

1

有4個地方上下文可以住。

  1. tomcatdir/CONF/server.xml中
  2. tomcatdir/CONF/context.xml中
  3. tomcatdir/CONF /卡塔利娜/本地主機/ appname.xml
  4. tomcatdir/web應用/應用程序的名字/ META-INF/context.xml

如果是tomcat 8,allowlinking屬性應該在Context中指定而不是在Resources標籤中指定。我tomcatdir/conf/context.xml文件看起來像這樣

<Context> 
<WatchedResource>WEB-INF/web.xml</WatchedResource> 
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource> 
<Resources allowLinking="true" cachingAllowed="true" cacheMaxSize="100000" /> 
</Context> 

該解決方案對我來說,現在工作得很好。但是我想分享一下我在進入這個解決方案之前所犯的錯誤。

我已經在tomcatdir/conf/server.xml和tomcatdir/conf/context.xml中定義了資源。 allowLinking =「true」僅在tomcatdir/conf/server.xml中設置。

我發現的是,如果你沒有指定allowLinking,它就等於將它設置爲false。所以我從server.xml中刪除了Resources標籤,並且只留下了tomcatdir/conf/context.xml中的allowLinking =「true」屬性。