[英]Nginx location regex capture variable
我有这个REST API URL:
http://localhost:4000/api/v2/stocks/accounts/1162/tradings
我希望它到proxy_pass到URL:
http://localhost:4001/api/v2/stocks/accounts/1162/tradings
其中1162是URL参数,可以是其他值。
我有以下内容:
location ^~ /api/v2/stocks/accounts/([^/]+)/tradings {
proxy_pass http://localhost:4001/api/v2/stocks/accounts/$1/tradings;
}
但它不起作用(404 Not Found),我搜索了类似的问题,但没有多大帮助:
像这样: 获取参数Nginx和proxy_pass的路径或者这个: 在nginx中使用位置正则表达式和重定向的麻烦 。
有没有办法实现我想要的,使用nginx?
在此先感谢您的帮助。
添加:
我还添加了参数捕获:
location ~ /api/v2/stocks/accounts/([^/]+)/tradings/(.*) {
proxy_pass http://localhost:4001/api/v2/stocks/accounts/$1/tradings/$2$is_args$args;
}
你可以这样做。 不' ^〜 '
location ~ /api/v2/stocks/accounts/([^/]+)/tradings {
proxy_pass http://localhost:4001/api/v2/stocks/accounts/$1/tradings;
}
如nginx.org所述 。
^〜经常匹配目录 ,如下所示:
location ^~ /dir/ {
# some actions
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.