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;
    }
}
阅读 7.3k
2 个回答

注意你路径中的斜杠,如果没有子目录把斜杠去了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题