nginx 不同路径代理不同地址

有这样的需求,www.domain.com/a 代理到 A 地址。www.domain.com/b 代理到 B 地址。

可以通过 nginx 实现。配置不是很复杂。

    # A
    location /a{
      proxy_pass http://www.other1.com:80/;
    }
    # B
    location /b { 
      proxy_pass http://www.other1.com:80/;
    }

proxy_pass 后面的url加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走。如果没有/,则会把匹配的路径部分也给代理走

访问的时候,不可省略最后一个 /,比如访问 A 时,地址为 www.domain.com/a/

如果可以,建议网站地址为 http://www/domain.com/a/index.html