Forum: NGINX Updating some old "if" statements

Posted by Ian M. Evans (Guest)
on 2012-09-27 21:36
(Received via mailing list)
A few years back this list helped me create some locations that allowed
some extensionless files to run as php and pass the rest of their path
along as a variable. I'm wondering if there's been any changes or tweaks
over the years that would make these locations run less efficiently than
they could be. As I'm reading this more I'm seeing "If is evil" right?

Location #1:

location ~ /(photos|profile|review|profiles|reviews|news)(/|$) {
if ($uri ~ ^(.*/(photos|profile|review|profiles|reviews|news))($|/.*)) {
rewrite ^(.*/(photos|profile|review|profiles|reviews|news))($|/.*)
$1.php?mypath=$3 last;
}
}

Location #2:

location ~ ^/galleries(/.*$|$) {
if (-f /usr/local/nginx/htdocs/pixcache$request_uri/index.html) {
expires 2h;
rewrite ^(.*)$ /pixcache$1/index.html last;
break;
}
rewrite ^/galleries(/.*$|$) /galleries.php?mypath=$1 last;
}
Posted by Edho Arief (Guest)
on 2012-09-28 13:16
(Received via mailing list)
On Fri, Sep 28, 2012 at 2:35 AM, Ian M. Evans <ianevans@digitalhit.com> 
wrote:
> rewrite ^(.*/(photos|profile|review|profiles|reviews|news))($|/.*)
> $1.php?mypath=$3 last;
> }
> }
>

just remove the if().

>
location ~ ^/galleries(?<mypath>/.*$|$) {
  expires 2h;
  try_files /pixcache$mypath/index.html /galleries.php?mypath=$mypath;
}
Posted by Ian Evans (Guest)
on 2012-09-29 03:39
(Received via mailing list)
Thanks for the new locations!

>>
>
> location ~ ^/galleries(?<mypath>/.*$|$) {
>    expires 2h;
>    try_files /pixcache$mypath/index.html /galleries.php?mypath=$mypath;
> }

I have an older PCRE with my CentOS version, so am I write in
remembering the named regex can be changed to from ?<mypath> to 
?P<mypath>

Thanks again.
Posted by Edho Arief (Guest)
on 2012-09-29 05:47
(Received via mailing list)
On Sat, Sep 29, 2012 at 8:38 AM, Ian Evans <ianevans@digitalhit.com> 
wrote:
>>> rewrite ^/galleries(/.*$|$) /galleries.php?mypath=$1 last;
> the named regex can be changed to from ?<mypath> to ?P<mypath>
>

I also wrote it wrong, should be /pixcache$request_uri/index.html
Posted by Ian M. Evans (Guest)
on 2012-09-29 22:47
(Received via mailing list)
On Fri, September 28, 2012 7:15 am, Edho Arief wrote:
> just remove the if().
Strangely, when I removed the "if" on this one and just had the rewrite, 
I
started getting 404 errors.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.