nginx ruoyi 配置静态资源服务
生活随笔
收集整理的這篇文章主要介紹了
nginx ruoyi 配置静态资源服务
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言
- nginx version: nginx/1.18.0
- CentOS Linux release 7.6.1810 (Core)
- ruoyi 4.6.0
需求
靜態資源目錄:/data/ruoyi/uploadPath。
配置靜態資源服務,且指向靜態資源目錄。
配置靜態資源服務
# static resourceslocation /static/ {alias /data/ruoyi/uploadPath/;}通過類似 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 resourceslocation /static/profile/ {rewrite /static/profile/(.*) /static/$1 last;}location /static/ {alias /data/flow-appdata/uploadPath/;}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 指向同一個物理路徑。
總結
以上是生活随笔為你收集整理的nginx ruoyi 配置静态资源服务的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: trackid怎么用?trackid曲目
- 下一篇: nginx 查看 $1,$2,$3