Welcome! Log In Create A New Profile

Advanced

nginx parse var in if file exist statement error?

est
November 02, 2011 02:35AM
Hi guys,

I found a stange bug in nginx 0.7.65, 0.8.54, and 1.0.6

Here is my setup of three machines


$ nginx -V
nginx version: nginx/0.7.65
TLS SNI support enabled
configure arguments: --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/body --http-proxy-temp-path=/var/lib/nginx/proxy --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --with-debug --with-http_stub_status_module --with-http_flv_module --with-http_ssl_module --with-http_dav_module --with-http_gzip_static_module --with-http_realip_module --with-mail --with-mail_ssl_module --with-ipv6 --add-module=/build/buildd/nginx-0.7.65/modules/nginx-upstream-fair


$nginx -V
nginx version: nginx/0.8.54
built by gcc 4.2.4 (Ubuntu 4.2.4-1ubuntu4)
configure arguments: --user=www-data --group=www-data --prefix=/usr/local/nginx --with-http_stub_status_module

$ nginx -V
nginx: nginx version: nginx/1.0.6
nginx: TLS SNI support enabled
nginx: configure arguments: --prefix=/etc/nginx/ --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwcgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6


So I have dir to store images, either jpg or png, the file name (image id) is unique. I want the URL to provide image id only, nginx to serve static jpg or png.

the config snippet is something like this:


server {
listen 80;
error_log /var/log/nginx/error_imglib.log debug;
root /home/develop/image_library;

location ~* ^/img/small/(\d+)/?$ {
set $fext 'jpg';
if (!-f '/home/develop/image_library/dump/$1-s.jpg'){
set $fext png;
}
alias '/home/develop/image_library/dump/$1-s.$fext' ;
}
}

When running curl it returls something like this


$ curl "http://127.0.0.1/img/small/1"
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.0.6</center>
</body>
</html>

Now the bug:

in three of my machines I set the error_log level to "debug", here is the output:

2011/11/02 14:01:09 [debug] 4194#0: *24 http script capture: "1"
2011/11/02 14:01:09 [debug] 4194#0: *24 http script copy: "-s."
2011/11/02 14:01:09 [debug] 4194#0: *24 http script var: "png"
2011/11/02 14:01:09 [debug] 4194#0: *24 http filename: "/home/steve/image_library/dump/1-s.png1
User-Agent"
2011/11/02 14:01:09 [debug] 4194#0: *24 add cleanup: 0833B2F0
2011/11/02 14:01:09 [error] 4194#0: *24 open() "/home/steve/image_library/dump/1" failed (2: No such file or directory), client: 127.0.0.1, request: "GET /img/small/1 HTTP/1.1"



2011/11/01 23:00:53 [alert] 7793#0: *38 "/home/develop/image_library/dump/1-s.jpgindex.html" is not a directory, request: "GET /img/small/1 HTTP/1.1"

2011/11/02 02:30:18 [error] 7666#0: *2491 open() "/home/develop/image_library/dump/1-s.pn" failed (2: No such file or directory), client: 127.0.0.1, request: "GET /img/small/1 HTTP/1.1"

2011/11/01 22:47:45 [error] 6740#0: *24 "/home/develop/image_library/dump/1-s.jpgTP/1.1
Hostindex.html" is not found (2: No such file or directory), request: "GET /img/small/1 HTTP/1.1"

So clearly somehow, nginx managed to mess HTTP headers into filename parser.

Can anyone help me? This is the weirdest bug I have ever encountered with nginx.
Subject Author Posted

nginx parse var in if file exist statement error?

est November 02, 2011 02:35AM

Re: nginx parse var in if file exist statement error?

Valentin V. Bartenev November 02, 2011 09:36AM

Re: nginx parse var in if file exist statement error?

est November 02, 2011 09:24PM

Re: nginx parse var in if file exist statement error?

Maxim Dounin November 02, 2011 09:52AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 290
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready