gpt4 book ai didi

NGINX proxy_pass 或 proxy_redirect

转载 作者:行者123 更新时间:2023-12-03 16:08:26 26 4
gpt4 key购买 nike

在 Nginx proxy_pass 上需要帮助。

从外部 Nginx URL 将像这样被击中:
http://some-IP:8080/v2/platform/general/activity/plan ?......

我的下游服务如下所示:
http://another-IP:8080/activity/plan ?...

我想摆脱

/v2/platform/general



从原始公共(public) url 并像上面一样调用我的下游服务。

在 Nginx 中,如何将公共(public)访问 URL 重定向到下游服务?

我试过这个:
location /v2/platform/general/ {
rewrite ^/(.*) /$1 break;
proxy_redirect off;
proxy_pass http://another-IP:8080;
proxy_set_header Host $host;

但它没有用,任何帮助表示赞赏。

最佳答案

proxy_passproxy_redirect具有完全不同的功能。 proxy_redirect指令仅涉及更改 Location 3xx 状态消息中的响应头。见 this document详情。

您的 rewrite语句除了阻止对 URI 的进一步修改之外什么都不做。此行需要删除,否则会禁止proxy_pass从映射URI。见下文。
proxy_pass指令可以通过将 URI 值附加到 /v2/platform/general/foo 来映射 URI(例如,从 /fooproxy_pass)值,与 location 结合使用值(value)。见 this document详情。

例如:

location /v2/platform/general/ {
...
proxy_pass http://another-IP:8080/;
}

仅当上游服务器未正确响应值 another-IP:8080 时,您可能需要设置 Host header .

您可能需要添加一个或多个 proxy_redirect如果您的上游服务器生成 3xx 状态响应且 Location 的值不正确,则声明 header 值。

关于NGINX proxy_pass 或 proxy_redirect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59852217/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com