静态资源映射

业务场景:系统上有个磁盘,里面存放了很多文件,有没有什么办法,能快速地访问这些文件。

tomcat配置

修改 server.xml 配置。

缺点显而易见,只要知道地址,就可以下载文件,这会被检测为系统漏洞。

因为独立于系统之外,系统内部代码很难限制文件的访问。

<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
       prefix="localhost_access_log" suffix=".txt"
       pattern="%h %l %u %t &quot;%r&quot; %s %b" />
           
  <Context path="/rgyx_files" docBase="C:/xxxxx" reloadable="true" crossContext="true"></Context>
</Host>

nginx配置

tomcat 与 nginx 某些角度来说,算是对标产品了,tomcat 有的功能 nginx 一般也会有,
因为暂未参与过相关配置,这里提供一下思路,你们自己百度了。

spring配置方式

这个配置的一般用途是,用于映射 WEB-INF 下的资源文件。其实,mvc:resources 也可以将路径映射到项目外的磁盘目录。

    <!-- 映射项目外的路径 -->
    <mvc:resources mapping="/${mapping_path}/**" location="file:${local_path}/">

    <!-- 映射各种静态资源:css、js等 -->
    <mvc:resources location="/WEB-INF/static/lib/" mapping="/lib/**" />

springboot的配置方式

    /**
     * 代码样例
     * @param registry -
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/seaboot/file/**").addResourceLocations("file:xxxxxxx");
            logger.debug("开放文件上传资源目录:" + uploadConstant.getRoot());
    }

posted on 2020-10-19 21:26  疯狂的妞妞  阅读(384)  评论(0编辑  收藏  举报

导航