需求
静态资源目录:/data/ruoyi/uploadPath。
配置静态资源服务,且指向静态资源目录。

配置静态资源服务

    # static resources
    location /static/ {
        alias   /data/ruoyi/uploadPath/;
    }
    
1
2
3
4
5
6
通过类似 http://test/static/upload/2021/04/15/6b24c663-1c04-4d0f-b608-8e7ba73c654f.jpg 这样的路径,可以访问到静态资源。

路径中添加个前缀
ruoyi中,上传功能返回两个路径,一个绝对路径(http开头),一个相对路径(/profile开头)。
相对路径为 /profile + 上传目录的相对路径。比如 profile/upload/2021/04/15/6b24c663-1c04-4d0f-b608-8e7ba73c654f.jpg对应的物理路径为/data/ruoyi/uploadPath/upload/2021/04/15/6b24c663-1c04-4d0f-b608-8e7ba73c654f.jpg。

为了兼容ruoyi,改为如下配置;

    # static resources
    location /static/profile/ {
        rewrite /static/profile/(.*) /static/$1 last;
    }
    location /static/ {
        alias   /data/flow-appdata/uploadPath/;
    }
1
2
3
4
5
6
7
http://test/static/upload/2021/04/15/6b24c663-1c04-4d0f-b608-8e7ba73c654f.jpg 、http://test/static/profile/upload/2021/04/15/6b24c663-1c04-4d0f-b608-8e7ba73c654f.jpg 指向同一个物理路径。
 

Logo

快速构建 Web 应用程序

更多推荐