gpt4 book ai didi

NGINX 配置 :

转载 作者:行者123 更新时间:2023-12-04 19:41:55 28 4
gpt4 key购买 nike

我是 NGINX 的新手,我正在尝试对我们的 ERP 网络服务器进行负载平衡。我有 3 个网络服务器在由 websphere 提供支持的端口 80 上运行,这对我来说是一个黑盒子:

* web01.example.com/path/apphtml
* web02.example.com/path/apphtml
* web03.example.com/path/apphtml

NGINX 正在监听虚拟 URL ourerp.example.com 并将其代理到集群。

这是我的配置:

upstream myCluster {
ip_hash;
server web01.example.com:80;
server web02.example.com:80;
server web03.example.com:80;
}

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name ourerp.example.com;
location / {
rewrite ^(.*)$ /path/apphtml break;
proxy_pass http://myCluster;
}
}

当我只使用 proxy_pass 时,NGINX 会负载平衡但会将请求转发到 web01.example.com 而不是 web01.example.com/path/apphtml

当我尝试添加 url 重写时,它只是重写了虚拟 URL,我最终得到了 ourerp.example.com/path/apphtml。

是否可以在上游级别进行 URL 重写或在上游级别将路径附加到应用程序?

最佳答案

如果您尝试通过代理将 / 映射到 /path/apphtml/,请使用:

proxy_pass http://myCluster/path/apphtml/;

参见 this document了解更多。

rewrite 语句的问题是替换字符串末尾缺少 $1。参见 this document有关更多信息,但正如我上面指出的,您不需要 rewrite 语句,因为 proxy_pass 语句无论如何都能够完成相同的工作。

关于NGINX 配置 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44730854/

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