On 2017-11-16 01:08:04 -0800, 'Mudasir Mirza' via openresty-en wrote:
> Hi,
>
> I am working on a solution in which I have just came across a scenario
> where I have to do following
>
> 1. Define upstream with multiple servers (at least 2) with weights
> 2. For the same location based on the server in the upstream selected,
> perform some URL rewriting then proxy pass to the server in upstream based
> on weight defined in upstream.
>
> I am unable to get this working.
>
> upstream app {
> # if this server is selected, then we need to perform some rewriting
> defined in location
> server bbb.app.com weight=5;
>
> # this can be the default server where we do not have to perform any
> rewriting in URL
> server aaa.app.com weight=95;
> }
>
> server {
> listen 80;
> server_name www.app.com
>
> location / {
>
> # IF upstream server is bbb.app.com, then we have to rewrite the URL
> rewrite ^ /beta-app/$request_uri;
> # END OF IF
>
> # For upstream server aaa.app.com , we dont want the rewrite
>
> proxy_pass http://app;
> }
>
> }
>
> If anyone can provide some basic example as to how I can make this work
> that will be really appreciated.
I think this can work.
upstream app {
server 127.0.0.1:8888 weight=5;
server aaa.app.com weight=95;
}
upstream appb {
server bbb.app.com;
}
server {
listen 80;
server_name www.app.com
location / {
proxy_pass http://app;
}
}
server {
listen 127.0.0.1:8888;
location / {
rewrite ^ /beta-app/$request_uri break;
proxy_pass http://appb;
}
}