Re[2]: bugs: try_files & if, add_header

Aleksander jjjx128 at mail.ru
Fri Oct 16 17:55:36 MSD 2009


> > Здравствуйте.
> > Есть пару проблем. 
> > 
> > Первая: не совсем работает try_files.
> > 
> > Есть такие файлы:
> > % find /tmp/test -type f
> > /tmp/test/hot/file2.txt
> > /tmp/test/file1.txt
> > 
> > И такой конфиг:
> > 
> >     server {
> >         listen 99;
> >         root /tmp/test;
> >         location / {
> >             try_files /hot$uri $uri =404;
> >         }
> >     }
> > 
> > На оба файла отдает нормальный ответ:
> > 
> > HEAD /file1.txt HTTP/1.0
> > 
> > HTTP/1.1 200 OK
> > Server: nginx/0.8.19
> > Date: Fri, 16 Oct 2009 13:12:21 GMT
> > Content-Type: text/plain
> > Content-Length: 6
> > Last-Modified: Fri, 16 Oct 2009 12:55:07 GMT
> > Connection: close
> > Accept-Ranges: bytes
> > 
> > 
> > HEAD /file2.txt HTTP/1.0
> > 
> > HTTP/1.1 200 OK
> > Server: nginx/0.8.19
> > Date: Fri, 16 Oct 2009 13:14:06 GMT
> > Content-Type: text/plain
> > Content-Length: 7
> > Last-Modified: Fri, 16 Oct 2009 12:55:24 GMT
> > Connection: close
> > Accept-Ranges: bytes
> > 
> > 
> > Но как только я добавляю в конфиг проверку с regexp'ом, try_files ломается:
> > 
> >     server {
> >         listen 99;
> >         root /tmp/test;
> >         location / {
> >             try_files /hot$uri $uri =404;
> >             if ($uri ~* \.txt$) {
> > 
> >             }
> >         }
> >     }
> 
>          location / {
>              try_files /hot$uri $uri =404;
>          }
> 
>          location ~ \.txt$ {
>              try_files /hot$uri $uri =404;
>          }

Нет, не в этом суть.
Это я для примера привел, на рабочем nginx'е мне нужно проверять $http_x_*,
$invalid_referer и другие, чтобы принимать решение отдавать файл 
или редиректить на CDN.

> > Отдает 404 на второй файл, как будто директивы try_files вообще нет.
> > 
> > HEAD /file1.txt HTTP/1.0
> > 
> > HTTP/1.1 200 OK
> > Server: nginx/0.8.19
> > Date: Fri, 16 Oct 2009 13:20:32 GMT
> > Content-Type: text/plain
> > Content-Length: 6
> > Last-Modified: Fri, 16 Oct 2009 12:55:07 GMT
> > Connection: close
> > Accept-Ranges: bytes
> > 
> > 
> > HEAD /file2.txt HTTP/1.0
> > 
> > HTTP/1.1 404 Not Found
> > Server: nginx/0.8.19
> > Date: Fri, 16 Oct 2009 13:20:52 GMT
> > Content-Type: text/html
> > Content-Length: 169
> > Connection: close
> > 
> > 
> > И вторая проблема: add_header не работает в контексте server, 
> > а только в location. 
> 
> 
> -- 
> Игорь Сысоев
> http://sysoev.ru
> 





More information about the nginx-ru mailing list