ПРОЕКТЫ 


  АРХИВ 


Apache-Talk @lexa.ru 

Inet-Admins @info.east.ru 

Filmscanners @halftone.co.uk 

Security-alerts @yandex-team.ru 

nginx-ru @sysoev.ru 


  СТАТЬИ 


  ПЕРСОНАЛЬНОЕ 


  ПРОГРАММЫ 



ПИШИТЕ
ПИСЬМА












     АРХИВ :: nginx-ru
Nginx-ru mailing list archive (nginx-ru@sysoev.ru)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: DAV + выделение regex + alias


  • To: nginx-ru@xxxxxxxxx
  • Subject: Re: DAV + выделение regex + alias
  • From: Maxim Dounin <mdounin@xxxxxxxxxx>
  • Date: Mon, 28 Apr 2014 22:31:25 +0400
  • In-reply-to: <CAL-L5YCaExnfdA_BMzaLG8udsurpW0id=kqsLXTrQhBYdD411g@mail.gmail.com>
  • References: <CAL-L5YCaExnfdA_BMzaLG8udsurpW0id=kqsLXTrQhBYdD411g@mail.gmail.com>

Hello!

On Mon, Apr 28, 2014 at 01:22:08PM +0400, Vadim Lazovskiy wrote:

> Здравствуйте.
> 
> Нужно разложить скиншоты по папкам и с таймстампом в имени файла. Вот
> конфиг:
> 
> server_name s2.domain.example.com;
> 
> ...
> 
> location /s/archive/ {
>     location ~
> "^/s/archive/screenshots/(?<timestamp>(?<dir>\d{8})\d{4})/(?<basename>\d+).(?<ext>[a-z0-9]+)$"
> {
> 
>         limit_except GET {
>             allow 10.10.1.18;
>             deny all;
>         }
> 
>         dav_methods PUT;
>         create_full_put_path on;
>         dav_access group:rw all:r;
> 
>         alias /disks/screenshots/$dir/$basename-$timestamp.$ext;
>         client_body_temp_path /disks/tmp;
>     }
> 
> ...
> 
> }
> 
> Вот запрос:
> 
> 10.10.1.18 - - [28/Apr/2014:12:59:12 +0400] "PUT
> /s/archive/screenshots/201404281043/0000000142.jpg HTTP/1.1" 201 25 "-"
> "curl/7.26.0"
> 
> Вот фрагмент debug-лога:

[...]

> 2014/04/28 12:59:12 [debug] 5297#0: *404 http script var: "201404281043"
> 2014/04/28 12:59:12 [debug] 5297#0: *404 http script copy: "."
> 2014/04/28 12:59:12 [debug] 5297#0: *404 http script var: "jpg"
> 2014/04/28 12:59:12 [debug] 5297#0: *404 http put filename:
> "/disks/screenshots/20140428/
> 0000000142-201404281043.jpgs2.domain.example.com"

[...]

> Ну и результат:
> 
> # find /disks/screenshots/
> /disks/screenshots/
> /disks/screenshots/20140428
> /disks/screenshots/20140428/0000000142-201404281043.jpgs2.domain.example.com

[...]

> Вопрос. Откуда берется домен в имени файла и как это побороть?

Выглядит как баг regex location + alias + limit_except/if.  
Собственно, для случая if он уже давно задокументирован на 
http://wiki.nginx.org/IfIsEvil.

Патч, видимо, какой-то такой:

# HG changeset patch
# User Maxim Dounin <mdounin@xxxxxxxxxx>
# Date 1398709755 -14400
#      Mon Apr 28 22:29:15 2014 +0400
# Node ID cf4f92f40290c9d3b8a8fb8cf836d3ebd16224f5
# Parent  539635cb8e98063b116555bdfd0c5ccfbfa8f184
Fixed alias in regex locations with limit_except/if.

The ngx_http_map_uri_to_path() function uses clcf->regex to detect if
it's working within a location given by a regular expression.  Its
behaviour was incorrect due to clcf->regex being false in implicit locations
created by if and limit_except.  Fix is to preserve clcf->regex within
implicit locations.

diff --git a/src/http/modules/ngx_http_rewrite_module.c 
b/src/http/modules/ngx_http_rewrite_module.c
--- a/src/http/modules/ngx_http_rewrite_module.c
+++ b/src/http/modules/ngx_http_rewrite_module.c
@@ -583,6 +583,7 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_
     clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
     clcf->loc_conf = ctx->loc_conf;
     clcf->name = pclcf->name;
+    clcf->regex = pclcf->regex;
     clcf->noname = 1;
 
     if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -4597,6 +4597,7 @@ ngx_http_core_limit_except(ngx_conf_t *c
     pclcf->limit_except_loc_conf = ctx->loc_conf;
     clcf->loc_conf = ctx->loc_conf;
     clcf->name = pclcf->name;
+    clcf->regex = pclcf->regex;
     clcf->noname = 1;
     clcf->lmt_excpt = 1;
 


-- 
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx-ru mailing list
nginx-ru@xxxxxxxxx
http://mailman.nginx.org/mailman/listinfo/nginx-ru


 




Copyright © Lexa Software, 1996-2009.