nginx's bug(alias and $request_uri to conflict)

Simon Liu simohayha.bobo at gmail.com
Mon Oct 11 06:46:28 MSD 2010


thanks!

my nginx version is 0.8.52, index.html in /home/my_name/tools/nginx/html/
, this is my nginx config:

 worker_processes  1;

error_log  logs/error.log  debug;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    expires         1y;
    sendfile        on;
    server {
        listen       8080;
        server_name  localhost;
        location ~*  ^/html/(.+\.html)$ {
            alias   /home/my_name/tools/nginx/html/$1;
            if ($request_uri ~ \.(html|htm|shtml)$) {
                expires     1h;
            }
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

and then exec  curl -I 127.0.0.1:8080/html/index.html:

HTTP/1.1 404 Not Found
Server: nginx/0.8.52
Date: Mon, 11 Oct 2010 02:24:25 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive

and this is error log:

2010/10/11 10:24:25 [debug] 8604#0: *1 http request line: "GET
/html/index.html HTTP/1.1"
2010/10/11 10:24:25 [debug] 8604#0: *1 http uri: "/html/index.html"
2010/10/11 10:24:25 [debug] 8604#0: *1 http args: ""
2010/10/11 10:24:25 [debug] 8604#0: *1 http exten: "html"
2010/10/11 10:24:25 [debug] 8604#0: *1 http process request header line
2010/10/11 10:24:25 [debug] 8604#0: *1 http header: "User-Agent: curl/7.21.1
(i686-pc-linux-gnu) libcurl/7.21.1 OpenSSL/1.0.0a zlib/1.2.5"
2010/10/11 10:24:25 [debug] 8604#0: *1 http header: "Host: 127.0.0.1:8080"
2010/10/11 10:24:25 [debug] 8604#0: *1 http header: "Accept: */*"
2010/10/11 10:24:25 [debug] 8604#0: *1 http header done
2010/10/11 10:24:25 [debug] 8604#0: *1 event timer del: 3: 2568703927
2010/10/11 10:24:25 [debug] 8604#0: *1 rewrite phase: 0
2010/10/11 10:24:25 [debug] 8604#0: *1 test location: "/50x.html"
2010/10/11 10:24:25 [debug] 8604#0: *1 test location: ~ "^/html/(.+\.html)$"
2010/10/11 10:24:25 [debug] 8604#0: *1 using configuration
"^/html/(.+\.html)$"
2010/10/11 10:24:25 [debug] 8604#0: *1 http cl:-1 max:1048576
2010/10/11 10:24:25 [debug] 8604#0: *1 rewrite phase: 2
2010/10/11 10:24:25 [debug] 8604#0: *1 http script var
2010/10/11 10:24:25 [debug] 8604#0: *1 http script var: "/html/index.html"
2010/10/11 10:24:25 [debug] 8604#0: *1 http script regex:
"\.(html|htm|shtml)$"
2010/10/11 10:24:25 [notice] 8604#0: *1 "\.(html|htm|shtml)$" matches
"/html/index.html", client: 127.0.0.1, server: localhost, request: "GET
/html/index.html HTTP/1.1", host: "127.0.0.1:8080"
2010/10/11 10:24:25 [debug] 8604#0: *1 http script if
2010/10/11 10:24:25 [debug] 8604#0: *1 post rewrite phase: 3
2010/10/11 10:24:25 [debug] 8604#0: *1 generic phase: 4
2010/10/11 10:24:25 [debug] 8604#0: *1 generic phase: 5
2010/10/11 10:24:25 [debug] 8604#0: *1 access phase: 6
2010/10/11 10:24:25 [debug] 8604#0: *1 access phase: 7
2010/10/11 10:24:25 [debug] 8604#0: *1 post access phase: 8
2010/10/11 10:24:25 [debug] 8604#0: *1 content phase: 9
2010/10/11 10:24:25 [debug] 8604#0: *1 content phase: 10
2010/10/11 10:24:25 [debug] 8604#0: *1 content phase: 11
2010/10/11 10:24:25 [debug] 8604#0: *1 http script copy:
"/home/my_name/tools/nginx/html/"
2010/10/11 10:24:25 [debug] 8604#0: *1 http script capture: "html"
2010/10/11 10:24:25 [debug] 8604#0: *1 http filename:
"/home/my_name/tools/nginx/html/htmlTTP/1.1
User-Agent"
2010/10/11 10:24:25 [debug] 8604#0: *1 add cleanup: 09C64B40
2010/10/11 10:24:25 [error] 8604#0: *1 open()
"/home/my_name/tools/nginx/html/htm" failed (2: No such file or directory),
client: 127.0.0.1, server: localhost, request: "GET /html/index.html
HTTP/1.1", host: "127.0.0.1:8080"
2010/10/11 10:24:25 [debug] 8604#0: *1 http finalize request: 404,
"/html/index.html?" a:1, c:1
2010/10/11 10:24:25 [debug] 8604#0: *1 http special response: 404,
"/html/index.html?"
2010/10/11 10:24:25 [debug] 8604#0: *1 http set discard body
2010/10/11 10:24:25 [debug] 8604#0: *1 HTTP/1.1 404 Not Found

and i remove  this line in nginx config :

 if ($request_uri ~ \.(html|htm|shtml)$) {
                expires      1h;
  }

and exec  curl -I 127.0.0.1:8080/html/index.html:

HTTP/1.1 200 OK
Server: nginx/0.8.52
Date: Mon, 11 Oct 2010 02:26:33 GMT
Content-Type: text/html
Content-Length: 158
Last-Modified: Sat, 05 Jun 2010 15:20:23 GMT
Connection: keep-alive
Expires: Tue, 11 Oct 2011 02:26:33 GMT
Cache-Control: max-age=31536000
Accept-Ranges: bytes

-- 
博观约取

豆瓣:www.douban.com/people/mustang/

blog: www.pagefault.info

twitter: www.twitter.com/minibobo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20101011/7063d7a9/attachment.html>


More information about the nginx mailing list