Set a particular location for address starting with '?'

I think I’ve tried all different approaches for this, but here is the
problem: I need to separate all URLs starting with ‘/?’ from the
remaining ones (eg /?p=12).

I’ve tried a bunch of different regex matches, but none of them seems to
be able to match URLs starting with a ‘?’. I already started a thread
here (http://forum.nginx.org/read.php?11,8435), but Jim referred me over
to the mailing list.

Configuration options I’ve tried includes:
‘location ^~ ?.* { proxy_pass http://blog.foobar.com;}’ and
‘location ~ /?.* { proxy_pass http://blog.foobar.com;}’

The above regexes should match the request, but for some reason they
don’t. Could anyone please provide me with a solution here?

Ps. Kudos to the deveopers for developing a great webserver. Compared to
Apache the configuration syntax is both easier to read and write. Ds.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,8769,8769#msg-8769

On Wed, 2009-09-23 at 19:38 -0400, mvip wrote:

I think I’ve tried all different approaches for this, but here is the problem: I need to separate all URLs starting with ‘/?’ from the remaining ones (eg /?p=12).

I’ve tried a bunch of different regex matches, but none of them seems to be able to match URLs starting with a ‘?’. I already started a thread here (http://forum.nginx.org/read.php?11,8435), but Jim referred me over to the mailing list.

Configuration options I’ve tried includes:
‘location ^~ ?.* { proxy_pass http://blog.foobar.com;}’ and
‘location ~ /?.* { proxy_pass http://blog.foobar.com;}’

The above regexes should match the request, but for some reason they don’t. Could anyone please provide me with a solution here?

That’s because Nginx doesn’t match locations on the query string. I
think you are most likely approaching this wrong anyway. Judging from
the little you’ve described, my guess is that you need to proxy any
request that can’t be mapped directly to an actual file:

location / {
root /path/to/root;
try_files $uri @myapp;
}

location @myapp {
proxy_pass http://blog.foobar.com;
}

Regards,
Cliff

Cliff,

Thanks for taking the time to answer my post. Unfortunately that didn’t
do the trick.

Let me try to explain the situation a bit better. I’m using Nginx as a
load balancer to proxy two different apps sitting on the same domain:
one Django app and one wordpress blog. I want to proxy ‘/’ and
‘/folder1’ to the django server and /?.* as well as everything else to
the wordpress server.

My current setup is as follows:
location / { proxy_pass http://blog.foobar.com;}
location = / {proxy_pass http://www.foobar.com; }
location ~ /admin/.* {proxy_pass http://www.foobar.com; }
location ~ /folder1/.* {proxy_pass http://www.foobar.com; }

It works great with the exception of that I cannot seem to filter out
all the /?.* calls.

What do you think is the best approach for this problem?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,8769,8943#msg-8943

Cliff, you’re my hero! =)

I modified it slightly and ended up with:

location = / {
if ($is_args) {
proxy_pass http://blog.foobar.com; # wordpress
}
proxy_pass http://www.foobar.com; # django
}

It works great and that is all that matters.

To address your question with sub-domain or folder – it’s a matter of
having a pretty URLs and a seamlessly integrated blog and site. =)

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,8769,8994#msg-8994

On Thu, 2009-09-24 at 09:30 -0400, mvip wrote:

My current setup is as follows:
location / { proxy_pass http://blog.foobar.com;}
location = / {proxy_pass http://www.foobar.com; }
location ~ /admin/.* {proxy_pass http://www.foobar.com; }
location ~ /folder1/.* {proxy_pass http://www.foobar.com; }

It works great with the exception of that I cannot seem to filter out
all the /?.* calls.

What do you think is the best approach for this problem?

Try this:

location / {
if ($is_args) {
proxy_pass http://blog.foobar.com; # wordpress
}
proxy_pass http://www.foobar.com; # django
}

However, what would make a lot more sense is to setup wordpress as
either a subdomain or under /blog or something. Then you could just
have a separate server section or location.

Regards,
Cliff

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs