Configure Symlinks for single directory in Tomcat

后端 未结 7 1121
情歌与酒
情歌与酒 2020-12-05 06:55

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 websi

相关标签:
7条回答
  • 2020-12-05 07:36

    Adding following line into conf/context.xml enables softlinks for me on apache tomcat 8.5+

    <Resources allowLinking="true" cachingAllowed="true" cacheMaxSize="100000">

    0 讨论(0)
  • 2020-12-05 07:37

    There are 4 places where Context can live.

    1. tomcatdir/conf/server.xml
    2. tomcatdir/conf/context.xml
    3. tomcatdir/conf/Catalina/localhost/appname.xml
    4. tomcatdir/webapps/appname/META-INF/context.xml

    In case of tomcat 8 allowlinking attribute should be specified not in Context but in Resources tag. My tomcatdir/conf/context.xml looks like this

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

    This solution works fine for me now. But I want to share also the mistake I had done before coming to this solution.

    I had defined Resources both in tomcatdir/conf/server.xml and in tomcatdir/conf/context.xml. And allowLinking="true" was set only in tomcatdir/conf/server.xml.

    What I found was that if you do not specify allowLinking it is equal to setting it to false. So I removed Resources tag from server.xml and left it only tomcatdir/conf/context.xml with the allowLinking="true" attribute in it.

    0 讨论(0)
  • 2020-12-05 07:42

    This works different in Tomcat 8+

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

    <Resources allowLinking="true" />
    
    0 讨论(0)
  • 2020-12-05 07:48

    I made it in this other way. I edit this other configuration file: apache-tomcat-7.0.33/conf/server.xml In Host tag I added:

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

    So, you can acces via: http://localhost/data

    0 讨论(0)
  • 2020-12-05 07:49

    Create a context.xml file in a META-INF directory in your web app containing:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <Context path="/myapp" allowLinking="true">
    
    </Context>
    

    more here: http://www.isocra.com/2008/01/following-symbolic-links-in-tomcat/

    0 讨论(0)
  • 2020-12-05 07:53

    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. :-)

    0 讨论(0)
提交回复
热议问题