How can i use Tomcat to serve image files from a public folder outside webapps? I dont want to use a 2nd Apache fileserver on a different port since the image files are part of the same app. And i dont want to create a symlink to the public folder inside webapps since my app is deployed as a war file....Is there a simpler solution similar to using default servlet for static content inside webapps, for static content outside outside webapps
相关问题
- Tomcat and SSL Client certificate
- Can't configure nginx as a proxy for tomcat wi
- Tomcat 8 how to remove sessionCookieName from URL
- tomcat websocket servlet listening port
- How to configure quartz scheduler with spring-styl
相关文章
- Tomcat的User信息可以存储到数据库中吗?
- tomcat的server.xml支持从Oracle中获取数据吗?
- web项目,Resonse Header发生解析错误,请大牛帮忙看看究竟是哪里的问题?
- Apache+Tomcat+JK实现的集群,如果Apache挂了,是不是整个服务就挂了?
- linux环境部署jpress,创建数据库时提提示连接失败
- Making a two way SSL authentication between apache
- Can't start Tomcat as Windows Service
- How to abort Tomcat startup upon exception in Serv
You can deploy an images folder as a separate webapp and define the location of that folder to be anywhere in the file system.
Create a Context element in an XML file in the directory
$CATALINA_HOME/conf/[enginename]/[hostname]/
where enginename might be 'Catalina' and hostname might be 'localhost'.Name the file based on the path URL you want the images to be viewed from, so if your webapp has path 'blog', you might name the XML file
blog#images.xml
and so that your images would be visible atexample.com/blog/images/
The content of the XML file should be
<Context docBase="/filesystem/path/to/images"/>
Be careful not to undeploy this webapp, as that could delete all your images!
Instead of configuring Tomcat to redirect requests, use Apache as a frontend with the Apache Tomcat connector so that Apache is only serving static content, while asking tomcat for dynamic content.
Using the JKmount directive (or others) you could specify exactly which requests are sent to Tomcat.
Requests for static content, such as images, would be served directly by Apache, using a standard virtual host configuration, while other requests, defined in the JKMount directive will be sent to Tomcat workers.
I think this implementation would give you the most flexibility and control on the overall application.
This is the way I did it and it worked fine for me. (done on Tomcat 7.x)
Add a
<context>
to thetomcat/conf/server.xml
file.Windows example:
Linux example:
Like this (in context):
In this way, you should be able to find the files (e.g.
/var/project/images/NameOfImage.jpg
) under:Many years later, we can do the following with Spring Web MVC, inside our
webapp-servlet.xml
file:In Tomcat 7, you can use "aliases" property. From the docs:
This is very simple and straight forward to server the static content from outside webapps folder in tomcat.
Simply edit the server.xml under $CATALINA_HOME/config/server.xml as below and restart the tomcat.
Add the context element inside the host element with two attribute docBase and path.
1) docBase: represents the hard drive directory 2) path: represents the uri on which you want to serve the static content.
For example:If you have 7.png inside the C:\Ankur\testFiles directory then you can access the 7.png file like below:
http://localhost:8081/companyLogo/7.png
For more details, check the blog