nginx ruoyi 配置静态资源服务

前言

  • nginx version: nginx/1.18.0
  • CentOS Linux release 7.6.1810 (Core)
  • ruoyi 4.6.0

需求

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

配置静态资源服务


    # static resources
    location /static/ {
        alias   /data/ruoyi/uploadPath/;
    }
    

通过类似 http://test/static/upload/2021/04/15/6b24c663-1c04-4d0f-b608-8e7ba73c654f.jpg 这样的路径,可以访问到静态资源。

兼容ruoyi

在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/ruoyi/uploadPath/;
    }

http://test/static/upload/2021/04/15/6b24c663-1c04-4d0f-b608-8e7ba73c654f.jpghttp://test/static/profile/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/ruoyi/uploadPath/;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值