我是NGINX的新手,我试图平衡我们的ERPnetworking服务器。 我有3个Web服务器运行在80端口的websphere,这是一个黑匣子给我:
* web01.example.com/path/apphtml * web02.example.com/path/apphtml * web03.example.com/path/apphtml
NGINX正在侦听虚拟URL ourerp.example.com并将其代理到集群。
这是我的configuration:
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追加到上游级别的应用程序?
如果您尝试通过代理映射/
到/path/apphtml/
,请使用:
proxy_pass http://myCluster/path/apphtml/;
请参阅此文档了解更多
rewrite
语句的问题是替换字符串末尾缺少$1
。 看到这个文件的更多,但正如我上面指出的,你不需要rewrite
语句,因为无论如何proxy_pass
语句是能够做同样的工作。