V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
ashes1122
V2EX  ›  NGINX

请教一个关于 nginx proxy_pass 的问题

  •  
  •   ashes1122 · 2020-08-11 18:31:27 +08:00 · 1538 次点击
    这是一个创建于 1326 天前的主题,其中的信息可能已经有所发展或是发生改变。

    希望 /a 匹配到 8.8.8.8,/b/a 匹配到 9.9.9.9

    location ~/a {

      proxy_pass  http://8.8.8.8;
    

    }

    location ~/b/a {

      proxy_pass  http://9.9.9.9;
    

    }

    但是这样写第二个匹配也会匹配到 8.8.8.8 上面,求教怎么样写可以 /b/a 匹配到 9.9.9.9

    4 条回复    2020-08-15 17:17:12 +08:00
    Cooky
        1
    Cooky  
       2020-08-11 18:36:49 +08:00 via Android   ❤️ 1
    正则吧
    nnd
        2
    nnd  
       2020-08-11 18:46:36 +08:00   ❤️ 1
    location /a {

    proxy_pass http://8.8.8.8;
    }

    location /b/a {

    proxy_pass http://9.9.9.9;
    }
    index90
        3
    index90  
       2020-08-11 19:10:24 +08:00   ❤️ 1
    正则匹配,第一个命中优先,换一下顺序就好了
    maxbon
        4
    maxbon  
       2020-08-15 17:17:12 +08:00
    加一个^
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2857 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 13:12 · PVG 21:12 · LAX 06:12 · JFK 09:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.