在Tomcat中为单个目录配置符号链接 [英] Configure Symlinks for single directory in Tomcat

查看:314
本文介绍了在Tomcat中为单个目录配置符号链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



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



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



仅在 test1 目录中的符号链接?我不想在任何地方启用符号链接,只是为了使 .pdf 文件的目录可用于web。

META-INF / context.xml 的解决方案有一些问题,包含< Context path =/ myappallowLinking =true>



最大的问题是如果 c> 中的 allowLinking META-INF / context.xml 优先于< Context> >。如果 conf / context.xml 没有明确定义 allowLinking ,那就是说 allowLinking =false。 (请参阅我的回答到上下文优先问题)



要确保您的应用程序允许链接,您必须说< Context override =trueallowLinking =true...& 。



另一个问题是 path =/ myapp a META-INF / context.xml 。为了防止混淆,最好不要使用。在服务器中只有 path < Context> 中有效。 xml ,以及官方Tomcat文档建议< Context> 放在 server.xml 中。



最后,我建议使用 conf / Catalina / 文件,而不是 myapp / META-INF / context.xml localhost / myapp.xml 文件。这种技术意味着你可以保持你的 META-INF 的内容清洁,这是你的webapp的胆量 - 我不喜欢冒险在内部的胆量我的webapp。 : - )


I have a directory to which a process uploads some .pdf files. This process is out of my control.

I need to make those files available through the website using Tomcat.

I have a directory /var/lib/tomcat5/webapps/test1 available to the web and I can see the files in it with a browser.

So, I created a symbolic link pointing at the directory with the .pdf files: /var/lib/tomcat5/webapps/test1/files/, but I can't see anything in that directory.

How can I enable symlinks in the test1 directory only? I don't want to enable symlinks everywhere, just so that directory with .pdf files is available to the web.

解决方案

There are a few problems with the solution of creating a META-INF/context.xml that contains <Context path="/myapp" allowLinking="true">

The biggest issue is that if a conf/context.xml exists, the allowLinking in the <Context> there takes precedence over a <Context> in a META-INF/context.xml. And if the in the conf/context.xml does not explicitly define allowLinking, that's the same as saying allowLinking="false". (see my answer to a context precedence question)

To be sure that your app allows linking, you have to say <Context override="true" allowLinking="true" ...>.

Another issue is that the path="/myapp" is ignored in a META-INF/context.xml. To prevent confusion, it's best to leave it out. The only time path in a <Context> has any effect is in the server.xml, and the official Tomcat docs recommend against putting <Context>s in a server.xml.

Finally, instead of a myapp/META-INF/context.xml file, I recommend using a conf/Catalina/localhost/myapp.xml file. This technique means you can keep the contents of your META-INF clean, which is the guts of your webapp -- I don't like to risk mucking about in the guts of my webapp. :-)

这篇关于在Tomcat中为单个目录配置符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆