一个带参数的请求发送到多个 Nginx 主机

我有一个关于 Nginx 后端服务请求路由的小问题。在我的场景中,我有一个前端服务和另一个日志服务,用于记录不同请求类型的 404 请求。

---> serviceFrontend/product/productName ----> if 404 ----> serviceLogger/?(productId=productName)

我怎么能在 serviceFrontend 服务触发时创建新请求并同时发送请求。

请帮帮我!


问题的解决

我使用 Nginx 中的 post_action 标注来解决了我的问题。

资源:

https://forum.nginx.org/read.php?2,275992,275992

点赞
用户1967498
用户1967498

你需要为 404 错误设置自定义错误位置,并将请求通过代理传递到你的上游。此外,你需要重写模块来设置查询字符串中的“ProductName”。类似于下面这个样子:

location /serviceFrontend/product {
    error_page 404 = @log404;
}

location @log404 {
    rewrite ^/serviceFrontend/product/(.*)$ /serviceLogger?productId=$1 break;
    proxy_pass http://logger.example.com;
}
2018-11-15 00:57:14