Opened 12 years ago

Closed 11 years ago

#234 closed defect (duplicate)

try_files with if

Reported by: Sergey Gorelkin Owned by: somebody
Priority: minor Milestone:
Component: nginx-core Version: 1.2.x
Keywords: Cc:
uname -a: Linux russia3 3.2.0-27-generic #43-Ubuntu SMP Fri Jul 6 14:25:57 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.2.1
built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
configure arguments: --prefix=/usr/nginx --with-cc-opt='-I /usr/include' --with-ld-opt='-L /usr/lib' --conf-path=/etc/nginx/conf/nginx.conf --sbin-path=/usr/sbin/nginx --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx-error.log --user=www --group=www --with-ipv6 --http-client-body-temp-path=/var/tmp/nginx/client_body_temp --http-proxy-temp-path=/var/tmp/nginx/proxy_temp --http-log-path=/var/log/nginx-access.log --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_stub_status_module --with-pcre

Description

Существует проблема совместного использования правила if и try_files.
Вот пример конфигурационного файла.

location ~ \.mp4$ {

if ($args ~* download) {

add_header Content-Disposition "attachment";

}
mp4;
expires -1;
mp4_buffer_size 1m;
mp4_max_buffer_size 40m;
access_log /logs/nginx/access.log main;
try_files /data2$uri $uri =404;

}

Скачать файл в виде
http://server/1234/video.mp4
Но если добавить параметр
http://server/1234/video.mp4?download=true
То сервер отвечает ошибку 404

Ставим любой другой параметр файл отдается.

Убираем условие if. Файл можно скачать.
Убираем if. Добавляем add_header. Тоже работает в любом варианте.

Change History (3)

comment:1 by Valentin V. Bartenev, 12 years ago

http://wiki.nginx.org/IfIsEvil#Examples - your problem is documented in the third example.

You should use the map directive:

map $arg_download $content_disposition {
    default       '';
    true          attachment;
}

...

add_header Content-Disposition $content_disposition;

Last edited 12 years ago by Valentin V. Bartenev (previous) (diff)

comment:2 by Sergey Gorelkin, 12 years ago

Thanks a lot. It's work.

But any way. It' very stange problem.
If I copy all data to one disk and remove try_files. Then my solution with if statement, also works.

Version 0, edited 12 years ago by Sergey Gorelkin (next)

comment:3 by Maxim Dounin, 11 years ago

Resolution: duplicate
sensitive: 0
Status: newclosed

That's a known problem with the "if" directive in location context - try_files doesn't work as it's not inherited into an implicit location created by if, see http://wiki.nginx.org/IfIsEvil. Closing this as duplicate of the ticket #86.

Note: See TracTickets for help on using tickets.