Welcome! Log In Create A New Profile

Advanced

Rewrite mirrored request

Posted by Jurian Broertjes 
Jurian Broertjes
Rewrite mirrored request
May 28, 2018 03:40PM
Hi All,

I'm trying to do a simple rewrite of a mirrored request, see the snippet
below. I'm under the impression that mirrored requests somehow cannot be
rewritten. Is this the case or am I doing something wrong here? Is there
some other way to get the job done?

  location / {
    mirror /mirror;
....
    proxy_pass http://slave;
  }

  location /mirror {
    internal;

    rewrite prd-solr solr;
    proxy_pass http://cloud;
  }


Best regards,
Jurian
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Roman Arutyunyan
Re: Rewrite mirrored request
May 28, 2018 06:00PM
Hello Jurian,

On Mon, May 28, 2018 at 03:38:45PM +0200, Jurian Broertjes wrote:
> Hi All,
>
> I'm trying to do a simple rewrite of a mirrored request, see the snippet
> below. I'm under the impression that mirrored requests somehow cannot be
> rewritten. Is this the case or am I doing something wrong here? Is there
> some other way to get the job done?
>
>   location / {
>     mirror /mirror;
> ....
>     proxy_pass http://slave;
>   }
>
>   location /mirror {
>     internal;
>
>     rewrite prd-solr solr;
>     proxy_pass http://cloud;
>   }

Mirror requests can be rewritten. But keep in mind that a mirror subrequest
has a different URI than the original request. In your case it's /mirror.
So unless 'prd-solr' matches it, rewrite will not happen.

Normally $request_uri is used to access the original request URI in a mirror
subrequest.

--
Roman Arutyunyan
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Jurian Broertjes
Re: Rewrite mirrored request
May 29, 2018 11:20AM
Hi Roman,

Thank you for your answer, but it's not clear to me how to do this.

The request I'd like to mirror is something like
http://solrproxy.example.org/prd-solr/abc/select?xyz, so I would expect
the "prd-solr" part to be rewritten for the mirror requests. The log says:

"GET /prd-solr/abc/select?xyz HTTP/1.0
Host: cloud

Do you have a suggestion on how to get it to "/solr/abc/select?xyz

Best regards,
Jurian


On 28-05-18 17:50, Roman Arutyunyan wrote:
> Hello Jurian,
>
> On Mon, May 28, 2018 at 03:38:45PM +0200, Jurian Broertjes wrote:
>> Hi All,
>>
>> I'm trying to do a simple rewrite of a mirrored request, see the snippet
>> below. I'm under the impression that mirrored requests somehow cannot be
>> rewritten. Is this the case or am I doing something wrong here? Is there
>> some other way to get the job done?
>>
>>   location / {
>>     mirror /mirror;
>> ....
>>     proxy_pass http://slave;
>>   }
>>
>>   location /mirror {
>>     internal;
>>
>>     rewrite prd-solr solr;
>>     proxy_pass http://cloud;
>>   }
> Mirror requests can be rewritten. But keep in mind that a mirror subrequest
> has a different URI than the original request. In your case it's /mirror.
> So unless 'prd-solr' matches it, rewrite will not happen.
>
> Normally $request_uri is used to access the original request URI in a mirror
> subrequest.
>

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Roman Arutyunyan
Re: Rewrite mirrored request
May 29, 2018 02:30PM
Hi Jurian,

On Tue, May 29, 2018 at 11:18:26AM +0200, Jurian Broertjes wrote:
> Hi Roman,
>
> Thank you for your answer, but it's not clear to me how to do this.
>
> The request I'd like to mirror is something like
> http://solrproxy.example.org/prd-solr/abc/select?xyz, so I would expect the
> "prd-solr" part to be rewritten for the mirror requests. The log says:
>
> "GET /prd-solr/abc/select?xyz HTTP/1.0
> Host: cloud
>
> Do you have a suggestion on how to get it to "/solr/abc/select?xyz

If the only reason why you need this rewrite is proxy_pass, then just pass it
a modified uri.

map $request_uri $new_uri {
~^/prd-solr/(.*)$ /solr/$1;
}

location /mirror {
internal;
proxy_pass http://cloud$new_uri;
}

> Best regards,
> Jurian
>
>
> On 28-05-18 17:50, Roman Arutyunyan wrote:
> >Hello Jurian,
> >
> >On Mon, May 28, 2018 at 03:38:45PM +0200, Jurian Broertjes wrote:
> >>Hi All,
> >>
> >>I'm trying to do a simple rewrite of a mirrored request, see the snippet
> >>below. I'm under the impression that mirrored requests somehow cannot be
> >>rewritten. Is this the case or am I doing something wrong here? Is there
> >>some other way to get the job done?
> >>
> >>   location / {
> >>     mirror /mirror;
> >>....
> >>     proxy_pass http://slave;
> >>   }
> >>
> >>   location /mirror {
> >>     internal;
> >>
> >>     rewrite prd-solr solr;
> >>     proxy_pass http://cloud;
> >>   }
> >Mirror requests can be rewritten. But keep in mind that a mirror subrequest
> >has a different URI than the original request. In your case it's /mirror.
> >So unless 'prd-solr' matches it, rewrite will not happen.
> >
> >Normally $request_uri is used to access the original request URI in a mirror
> >subrequest.
> >
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

--
Roman Arutyunyan
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Jurian Broertjes
Re: Rewrite mirrored request
May 30, 2018 10:00AM
Hi Roman,

That seems to work, thanks!

Best regards,
Jurian

On 29-05-18 14:28, Roman Arutyunyan wrote:
> Hi Jurian,
>
> On Tue, May 29, 2018 at 11:18:26AM +0200, Jurian Broertjes wrote:
>> Hi Roman,
>>
>> Thank you for your answer, but it's not clear to me how to do this.
>>
>> The request I'd like to mirror is something like
>> http://solrproxy.example.org/prd-solr/abc/select?xyz, so I would expect the
>> "prd-solr" part to be rewritten for the mirror requests. The log says:
>>
>> "GET /prd-solr/abc/select?xyz HTTP/1.0
>> Host: cloud
>>
>> Do you have a suggestion on how to get it to "/solr/abc/select?xyz
> If the only reason why you need this rewrite is proxy_pass, then just pass it
> a modified uri.
>
> map $request_uri $new_uri {
> ~^/prd-solr/(.*)$ /solr/$1;
> }
>
> location /mirror {
> internal;
> proxy_pass http://cloud$new_uri;
> }
>
>> Best regards,
>> Jurian
>>
>>
>> On 28-05-18 17:50, Roman Arutyunyan wrote:
>>> Hello Jurian,
>>>
>>> On Mon, May 28, 2018 at 03:38:45PM +0200, Jurian Broertjes wrote:
>>>> Hi All,
>>>>
>>>> I'm trying to do a simple rewrite of a mirrored request, see the snippet
>>>> below. I'm under the impression that mirrored requests somehow cannot be
>>>> rewritten. Is this the case or am I doing something wrong here? Is there
>>>> some other way to get the job done?
>>>>
>>>>   location / {
>>>>     mirror /mirror;
>>>> ....
>>>>     proxy_pass http://slave;
>>>>   }
>>>>
>>>>   location /mirror {
>>>>     internal;
>>>>
>>>>     rewrite prd-solr solr;
>>>>     proxy_pass http://cloud;
>>>>   }
>>> Mirror requests can be rewritten. But keep in mind that a mirror subrequest
>>> has a different URI than the original request. In your case it's /mirror.
>>> So unless 'prd-solr' matches it, rewrite will not happen.
>>>
>>> Normally $request_uri is used to access the original request URI in a mirror
>>> subrequest.
>>>
>> _______________________________________________
>> nginx mailing list
>> nginx@nginx.org
>> http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login