How to catch a request that has a given word in url?

Hi,

I am trying to catch any request that has WORD in the url, eg:

catch: http://example.org/whatever/path/WORD/file.pdf

don’t catch: http://example.org/some/other/path/anotherfile.jpg

and if simple to do, don’t catch: http://example.org/folder/WORD.doc

I tried:

location ^~ /WORD/ {}

location WORD {}

location ~* WORD {}

But none seemed to do want I want*.

Thanks for your advice :slight_smile:

*: unless I’m hitting again this stupid caching thing, but this time I
tried in safari and it didn’t work either, so it should be cleared.

On Mon, Aug 09, 2010 at 11:16:53AM +0200, Fernando P. wrote:

Thanks for your advice :slight_smile:

Place

location ~ /WORD/ {

}

as the first location in a server.


Igor S.
http://sysoev.ru/en/

Place

location ~ /WORD/ {

}

as the first location in a server.

I have placed as the first location of my server:

location ~ /WORD/ {
internal;
root …
}

But it still gets served directly by nginx. I’d like to use it with
X-Accel-Redirect, but first I need to make sure that people can’t access
these files directly.

I’ll use actual values:

A public request looks like:

/uploads/2009/product.jpg

An a restricted request looks like:

/uploads/2009/restricted/product.mp4

So I have:

location ~ /restricted/ {
internal;
root …;
}

location ^~ /uploads/ {
root …;
}

Is it my /uploads/ location which fits maybe better the request and
confuses nginx?

On Mon, Aug 09, 2010 at 11:53:30AM +0200, Fernando P. wrote:

location ~ /WORD/ {
internal;
root …
}

But it still gets served directly by nginx. I’d like to use it with
X-Accel-Redirect, but first I need to make sure that people can’t access
these files directly.

Could you create a debug log of the request:
http://nginx.org/en/docs/debugging_log.html
?


Igor S.
http://sysoev.ru/en/

Finally I managed to make everything work.

“^~” disables regex locaitons testing, so you need something liek this:
I never really understood the docs about that.

But I don’t really understand these ~, ^~ and what have you. They seem
to affect other locations which is not obvious at first sight.

Thanks for your impressive support Igor.

On Mon, Aug 09, 2010 at 12:20:13PM +0200, Fernando P. wrote:

Finally I managed to make everything work.

“^~” disables regex locaitons testing, so you need something liek this:
I never really understood the docs about that.

But I don’t really understand these ~, ^~ and what have you. They seem
to affect other locations which is not obvious at first sight.

http://wiki.nginx.org/NginxHttpCoreModule#location


Igor S.
http://sysoev.ru/en/

On Mon, Aug 09, 2010 at 11:59:02AM +0200, Fernando P. wrote:

}

Is it my /uploads/ location which fits maybe better the request and
confuses nginx?

“^~” disables regex locaitons testing, so you need something liek this:

location ~ /restricted/ {
internal;
root …;
}

location /uploads/ {
root …;
}


Igor S.
http://sysoev.ru/en/

http://www.oxpdf.de/

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

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