在Tomcat中为单个目录配置符号链接

时间:2008-11-24 19:05:39

标签: configuration tomcat symlink

我有一个进程上传一些.pdf文件的目录。这个过程不受我的控制。

我需要使用Tomcat通过网站提供这些文件。

我有一个可用于网络的目录/var/lib/tomcat5/webapps/test1,我可以通过浏览器查看其中的文件。

所以,我创建了一个指向包含.pdf文件的目录的符号链接: /var/lib/tomcat5/webapps/test1/files/,但我在该目录中看不到任何内容。

如何仅在test1目录中启用符号链接?我不想在任何地方启用符号链接,只是为了使网络上有.pdf个文件的目录。

7 个答案:

答案 0 :(得分:49)

创建包含META-INF/context.xml的{​​{1}}的解决方案存在一些问题

最大的问题是,如果<Context path="/myapp" allowLinking="true">存在,则conf/context.xml中的allowLinking<Context>中的{{>>优先于 <Context> {1}}。如果META-INF/context.xml中的conf/context.xml未明确定义allowLinking,则与allowLinking="false"相同。 (请参阅my answer到上下文优先级问题)

为确保您的应用允许关联,您必须说<Context override="true" allowLinking="true" ...>

另一个问题是path="/myapp"中忽略了META-INF/context.xml。为了防止混淆,最好不要混淆。 path<Context>server.xml唯一有效的时间是<Context>,而official Tomcat docs recommend against server.xml位于myapp/META-INF/context.xml。< / p>

最后,我推荐使用conf/Catalina/localhost/myapp.xml文件,而不是META-INF文件。这种技术意味着你可以保持{{1}}的内容干净,这是你的webapp的胆量 - 我不喜欢冒险在我的webapp的内容中捣乱。 : - )

答案 1 :(得分:16)

在您的网络应用中的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/

答案 2 :(得分:6)

是的我知道这是一个老问题,但是我发现了一个新的解决方案,使用带有--bind选项而不是符号链接的mount,并且tomcat不需要任何重新配置​​:

cd / var / lib / tomcat5 / webapps / test1 /

mkdir文件

mount --bind / path / to / actual / upload / directory / files files

答案 3 :(得分:4)

这在Tomcat 8 +

中有所不同

http://tomcat.apache.org/migration-8.html

<Resources allowLinking="true" />

答案 4 :(得分:3)

Context可以存在4个地方。

  1. tomcatdir / CONF / server.xml中
  2. tomcatdir / CONF / context.xml中
  3. tomcatdir / CONF /卡塔利娜/本地主机/ appname.xml
  4. tomcatdir / web应用/应用程序的名字/ META-INF / context.xml中
  5. 如果是tomcat 8,则不应在Context中指定allowlinking属性,而应在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”属性。

答案 5 :(得分:1)

我用另一种方式做到了。 我编辑其他配置文件:apache-tomcat-7.0.33 / conf / server.xml Host 标记中,我添加了:

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

因此,您可以通过:http://localhost/data

进行访问

答案 6 :(得分:0)

在conf / context.xml中添加以下行可在apache tomcat 8.5+上为我启用软链接

<< strong>资源allowLinking =“ true” cachingAllowed =“ true” cacheMaxSize =“ 100000” >

相关问题