我是新来的NGINX,我试图负载平衡我们的ERP网络服务器。我有3台webserver运行在由websphere驱动的80端口上,对我来说这是一个黑匣子:
* web01.example.com/path/apphtml
* web02.example.com/path/apphtml
* web03.example.com/path/apphtmlNGINX正在侦听虚拟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重写,或者在上游级别为应用程序追加路径?
发布于 2017-06-24 09:51:30
如果您试图通过代理将/映射到/path/apphtml/,请使用:
proxy_pass http://myCluster/path/apphtml/;有关更多信息,请参见本文件。
rewrite语句的问题是替换字符串末尾缺少一个$1。有关更多信息,请参见本文件,但正如我前面指出的,您不需要rewrite语句,因为proxy_pass语句无论如何都能够执行相同的任务。
https://stackoverflow.com/questions/44730854
复制相似问题