Nginx Location Block 和 Proxy Pass 的正则表达式

Regular Expression for Nginx Location Block and Proxy Pass

想请教一下Nginx的一些配置; 如何在 Nginx 位置块中设置正则表达式?这是我的配置

location ~ ^/web/api/v1/([A-Za-z]+) {
    proxy_pass http://localhost:5000/;
}

因此,此配置的用例是当我键入 "localhost/web/api/v1/apple" 时它将路由到 localhost:5000/apple,"localhost/web/api/v1/pineapple" 它将路由到 localhost:5000/pineapple , 等等。注:apple 和 pineapple 仅示例路径名。

谢谢

此讨论归功于@Richard Smith:https://serverfault.com/questions/1005685/how-to-set-regular-expression-for-nginx-location-block-and-proxy-pass/1005697#1005697

我将配置更改为:

location ~ ^/web/api/v1/([A-Za-z]+)$ {
   proxy_pass http://127.0.0.1:5000/;
}

localhost 变成 127.0.0.1