Forum: NGINX Case insensitive location

2974d09ac2541e892966b762aad84943?d=identicon&s=25 Callumpy (Guest)
on 2014-04-08 14:55
(Received via mailing list)
Hello there, i'm hoping someone can help me out with this. I've tried
many
different things but none have worked for me so far.

Here is my location block:

location ^~ /card/ {
                root /home/site/public;
                rewrite ^/card/([a-zA-Z0-9_+]+)/(.*).png$
/card.php?name=$2&type=$1 last;
                expires epoch;
        }

Some requests for images are being made with a capital 'C' in 'Card' and
are
causing 404s.

I've tried changing the location to "~* ^/card/" but that didn't work,
is
there anything else I could try?

Thanks in advance.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,249105,249105#msg-249105
1266aa99d1601b47bbd3ec22affbb81c?d=identicon&s=25 B.R. (Guest)
on 2014-04-08 15:32
(Received via mailing list)
As the location
docs<http://nginx.org/en/docs/http/ngx_http_core_module...,
the solution you provided should work.

Ensure that:
1°) You are working with the right binary
2°) Configuration syntax is correct (nginx -t) and reload was successful
(no message in that direction in the error logs), thus effectively
reloading the configuration
3°) Requests starting with C and returning errors are matching the regex
being used
4°) The precedence of location syntax does not make another location
block
capturing the request (since requests are matched by one and only one
location block every time), thus having the requjest served incorrectly
(and returning 404 since content could not be found in the serving
location
block)
---
*B. R.*
2974d09ac2541e892966b762aad84943?d=identicon&s=25 Callumpy (Guest)
on 2014-04-08 18:52
(Received via mailing list)
Thank you for the reply.

As far as I know, everything is fine, but it's still not working for me.

When I disable caching, which includes pngs, and then use 'location ~*
^/card', I am able to access the images normally without capital
letters,
but still not with capitals.

With caching enabled, I cannot access images at all with the 'location
~*
^/card' setup.

Caching is the main reason for me needing '^~' on my location block, so
that
I can disable caching for these images alone.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,249105,249120#msg-249120
1266aa99d1601b47bbd3ec22affbb81c?d=identicon&s=25 B.R. (Guest)
on 2014-04-08 19:18
(Received via mailing list)
I do not know about caching nor do I take it into consideration as it is
not part of the problem as stated.

You stated that the location regex was the problem and you seem to have
taken the proper checks to verify the proper location is being used,
hence
I assume the location regex is not the problem.

I see another regex in the location block, in the rewrite directive,
which
does not seem to be prepared to face different sensitivities of the
case.
I guess you should follow that lead...
Please check your rewrite regex against case-sensitivity or, since the
regex match is already done at location level and you do not need
another
one, maybe consider using the
return<http://nginx.org/en/docs/http/ngx_http_rewrite_mod...
instead.
---
*B. R.*
2974d09ac2541e892966b762aad84943?d=identicon&s=25 Callumpy (Guest)
on 2014-04-11 13:59
(Received via mailing list)
I'm still having no luck with it.

As I said before, when I use location ~* ^/card/, it just 404s all the
time
unless I disable my cache.

Here is my cache code, I have no idea why it does this.

# Cache setup.
        location ~*  \.(jpg|jpeg|png|gif|ico|css|xml|js|woff)$ {
                expires 30d;
                root /home/site/public;
                add_header Pragma public;
                add_header Cache-Control "public, must-revalidate,
proxy-revalidate";
        }

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,249105,249224#msg-249224
2974d09ac2541e892966b762aad84943?d=identicon&s=25 mex (Guest)
on 2014-04-11 15:15
(Received via mailing list)
do you have tryfiles enabled?

i'd try this to check, if the request reaches the nright location-block


location ^~ /card/ {
           ...
          access_log /var/log/nginx/cards.log combined;
          ...
         }

if so, your must look inside your locatiuon, if not, somwhere else


regards,


mex

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,249105,249226#msg-249226
40b4c848b8fcd63b0cb60b9d170c3a77?d=identicon&s=25 Valentin V. Bartenev (Guest)
on 2014-04-11 15:23
(Received via mailing list)
On Friday 11 April 2014 07:59:42 Callumpy wrote:
>                 root /home/site/public;
>                 add_header Pragma public;
>                 add_header Cache-Control "public, must-revalidate,
> proxy-revalidate";
>         }
>


A quote from the documentation (http://nginx.org/r/location):

   "Then regular expressions are checked, in the order of their
appearance
    in the configuration file. The search of regular expressions
terminates
    on the first match, and the corresponding configuration is used."

Let me guess, your "Cache setup" comes first?

  wbr, Valentin V. Bartenev
2974d09ac2541e892966b762aad84943?d=identicon&s=25 Callumpy (Guest)
on 2014-04-11 20:43
(Received via mailing list)
Oh my, what an idiot i've been. Thank you very much for your post!

I moved it up above my cache and it works just fine, here is what i've
been
able to shorten it down to now:

 location ~* /card/ {
                rewrite (?i)^/card/([a-zA-Z0-9_+]+)/(.*).png$
/card.php?name=$2&type=$1;
                expires epoch;
        }

Thank you to everyone who posted to help me, it's greatly appreciated!

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,249105,249235#msg-249235
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.