首頁  >  問答  >  主體

vue.js - nginx反向代理location順序問題

以下符合規則,我的目的是

  1. 以/api/img 開頭的靜態圖片,反向代理到http://localhost:8084/,如/api/img/default.png代理程式到http://localhost:8084/default. ..

  2. 以/api/img/cdn/ 開頭的靜態圖片,反向代理到cdn上http://clouddn.com/,如/api/img/cdn/default.png代理到http:/ /clouddn.com/default.png

第一條可以實現,第二條無法實現,謝謝幫忙修改
server {

    listen    8085;
    server_name        localhost;
    location /api/v1 { 
        proxy_pass http://localhost:8084/api/v1;
    }

    location ^~ /api/img/cdn/ { 
        proxy_pass http://clouddn.com/;
    }
    location /api/img { 
        proxy_pass http://localhost:8084/;
    }

    location / {
        root  html/vue2;
        index  index.html index.htm;
    }
}
高洛峰高洛峰2713 天前819

全部回覆(2)我來回復

  • 我想大声告诉你

    我想大声告诉你2017-05-16 17:10:49

    把^~ /api/img/cdn/改成/api/img/cdn/呢,或~ /api/img/cdn/,看一下location匹配規則,參考http://seanlook.com/2015/05 /1...

    回覆
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-16 17:10:49

    注意你路徑中的斜杠,如果沒有子目錄把斜杠去了

    回覆
    0
  • 取消回覆