#304 closed defect (invalid)
rewrite break doesn't work with index
| Reported by: | Mike Robertson | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | nginx-module | Version: | 1.3.x |
| Keywords: | Cc: | ||
| uname -a: | Darwin supamac.local 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64 i386 iMac11,1 Darwin | ||
| nginx -V: |
nginx version: nginx/1.3.10
built by clang 4.0 (tags/Apple/clang-421.0.60) (based on LLVM 3.1svn) TLS SNI support enabled configure arguments: --prefix=/usr/local/Cellar/nginx/1.3.10 --with-http_ssl_module --with-pcre --with-ipv6 --with-cc-opt=-I/usr/local/include --with-ld-opt=-L/usr/local/lib --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp --with-pcre-jit |
||
Description
The rewrite doesn't interact properly with the index command.
Suppose I have this configuration:
events {}
http {
include mime.types;
default_type text/plain;
server {
listen 8080;
location / {
return 200 "requested $document_uri";
}
location ~ ^/~(?<user>[^/]+) {
root "/Users/$user/Sites";
index index.html;
rewrite ^[^/]*/~(?<user>[^/]+)(?<rest>.*)$ $rest break;
}
}
}
I expect when I do a request for ~mikerobe/ that it will remap the request to the local file /Users/mikerobe/Sites/index.html (which exists). However, when I submit the request, nginx incorrectly hits the location / block.
mikerobe supamac> cat get.tcp GET /~mikerobe/ HTTP/1.1 Host: localhost Connection: close mikerobe supamac> cat get.tcp|nc localhost 8080 HTTP/1.1 200 OK Server: nginx/1.2.6 Date: Mon, 18 Feb 2013 16:47:20 GMT Content-Type: text/html Content-Length: 21 Connection: close requested /index.html
Only if I change the request to ~mikerobe/index.html does it return the expected page:
mikerobe supamac> cat get.tcp
GET /~mikerobe/index.html HTTP/1.1
Host: localhost
Connection: close
mikerobe supamac> cat get.tcp|nc localhost 8080
HTTP/1.1 200 OK
Server: nginx/1.2.6
Date: Mon, 18 Feb 2013 16:49:27 GMT
Content-Type: text/html
Content-Length: 83
Last-Modified: Mon, 18 Feb 2013 16:39:49 GMT
Connection: close
Accept-Ranges: bytes
<html>
<head>
<title>Real Index</title>
</head>
<body>
</body>
</html>
Change History (3)
comment:1 by , 13 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
comment:2 by , 13 years ago
So is there a straightforward way to get the desired behavior in this case? (without having to do another slow regex match) Are you supposed to use try_files for this?
comment:3 by , 13 years ago
Ah, ok I guess you use an alias. Sorry. :) (I hadn't looked at your UserDir link)
Note:
See TracTickets
for help on using tickets.

The index directive does internal redirect to a current uri with "index.html" added, see http://nginx.org/en/docs/http/request_processing.html and http://nginx.org/r/index for details. With your configuration request to "/~mikerobe/" becomes "/" after the rewrite, and then index directive does an internal redirect to "/index.html". No surprise it is processed in the "location /".
See also http://wiki.nginx.org/UserDir, which is probably what you are trying to do.