Welcome! Log In Create A New Profile

Advanced

Redirect certain GET variables

Posted by mvip 
Redirect certain GET variables
September 22, 2009 12:52PM
I've tried quite a few different options, but neither of them worked out, but this is what I want to accomplish: All GET strings starting with p= or s= should be sent to a different bac-end server.

I tried this:

location / {
if ($args ~* ^(s=.*|p=.*)) {
proxy_pass http://blog.foobar.com;
break;}
proxy_pass http://www.foobar.com; }

I also tried simply doing

location ~ ^/(\?s.*|\?p.*) {
proxy_pass http://blog.foobar.com;}

Neither of those two options worked out. Can anyone help me out?
Re: Redirect certain GET variables
September 22, 2009 01:46PM
Are the requests coming in on those separate hosts - ie blog.foobar.com and foobar.com?

If so, the easy way is with separate server blocks. Assuming the backends are local, something like:

[code]
server {
...
server_name blog.foobar.com;
...
location / {
proxy_pass http://10.0.0.2;
}
}

server {
...
server_name foobar.com;
...
location / {
proxy_pass http://10.0.0.3;
}
}

[/code]

I'm guessing that it isn't that simple however. :(

Short of that, something like:

[code]
location ~* ^(s=.*|p=.*)$ {
proxy_pass http://blog.foobar.com;
...
}

location / {
proxy_pass http://foobar.com;
...
}
[/code]

might work.

I've never used this type of configuration but according to http://wiki.nginx.org/NginxHttpCoreModule#location a location with a regular expression match will be used before a location with a "conventional string" which should be how "location /" is handled.

--
Jim Ohlstein
Re: Redirect certain GET variables
September 23, 2009 12:43PM
Jim,
Thanks for replying on my post. Please find my comments below.

Jim Ohlstein Wrote:
-------------------------------------------------------
> Are the requests coming in on those separate hosts
> - ie blog.foobar.com and foobar.com?
>
> If so, the easy way is with separate server
> blocks. Assuming the backends are local, something
> like:
>
>
> server {
> ...
> server_name blog.foobar.com;
> ...
> location / {
> proxy_pass http://10.0.0.2;
> }
> }
>
> server {
> ...
> server_name foobar.com;
> ...
> location / {
> proxy_pass http://10.0.0.3;
> }
> }
>
>

I wish it was that easy, but both requests are towards same domain (www.foobar.com).

>
> I'm guessing that it isn't that simple however.
> :(
>
> Short of that, something like:
>
>
> location ~* ^(s=.*|p=.*)$ {
> proxy_pass http://blog.foobar.com;
> ...
> }
>
> location / {
> proxy_pass http://foobar.com;
> ...
> }

Unfortunately that doesn't work. I've already tried it. For some reason that won't match the request.

Actually, a condition matching urls starting /? would be even better (that is ^/\?.*).

>
>
> might work.
>
> I've never used this type of configuration but
> according to
> http://wiki.nginx.org/NginxHttpCoreModule#location
> a location with a regular expression match will be
> used before a location with a "conventional
> string" which should be how "location /" is
> handled.
Re: Redirect certain GET variables
September 23, 2009 12:50PM
mvip Wrote:
-------------------------------------------------------
> Jim,
> Thanks for replying on my post. Please find my
> comments below.
>
> Jim Ohlstein Wrote:
> --------------------------------------------------
> -----
> > Are the requests coming in on those separate
> hosts
> > - ie blog.foobar.com and foobar.com?
> >
> > If so, the easy way is with separate server
> > blocks. Assuming the backends are local,
> something
> > like:
> >
> >
> > server {
> > ...
> > server_name blog.foobar.com;
> > ...
> > location / {
> > proxy_pass http://10.0.0.2;
> > }
> > }
> >
> > server {
> > ...
> > server_name foobar.com;
> > ...
> > location / {
> > proxy_pass http://10.0.0.3;
> > }
> > }
> >
> >
>
> I wish it was that easy, but both requests are
> towards same domain (www.foobar.com).
>
> >
> > I'm guessing that it isn't that simple however.
> > :(
> >
> > Short of that, something like:
> >
> >
> > location ~* ^(s=.*|p=.*)$ {
> > proxy_pass http://blog.foobar.com;
> > ...
> > }
> >
> > location / {
> > proxy_pass http://foobar.com;
> > ...
> > }
>
> Unfortunately that doesn't work. I've already
> tried it. For some reason that won't match the
> request.

Have you tried matching each variable in separate location blocks? Or maybe using "location ^~"?

>
> Actually, a condition matching urls starting /?
> would be even better (that is ^/\?.*).
>
> >
> >
> > might work.
> >
> > I've never used this type of configuration but
> > according to
> >
> http://wiki.nginx.org/NginxHttpCoreModule#location
>
> > a location with a regular expression match will
> be
> > used before a location with a "conventional
> > string" which should be how "location /" is
> > handled.

--
Jim Ohlstein
Re: Redirect certain GET variables
September 23, 2009 01:18PM
Unfortunately that didn't do the trick either.

I tried both with more precise variables as well as this one (along with a few different versions of it):

location ^~ \?.* { proxy_pass http://blog.foobar.com;}

Could it possibly be a bug in Nginx that prevents it from matching 'locations' when they start with '?'
Re: Redirect certain GET variables
September 23, 2009 02:05PM
I don't know. It is possible. I suggest posting this to the mailing list forum. Igor will undoubtedly be able to help more than I can.

--
Jim Ohlstein
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 262
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready