Opened 4 years ago

Closed 4 years ago

#1113 closed defect (invalid)

root variable in location reset to default value (/usr/share/nginx/html) when using rewrite in this location

Reported by: Shi3A@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.10.x
Keywords: Cc:
uname -a: Linux localserver 4.7.0-1-amd64 #1 SMP Debian 4.7.5-1 (2016-09-26) x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.10.1


"root" changes to global value (defined in server section or /usr/share/nginx/html if root not defined), and redefine "root" in location haven't any result.
server {

server_name local;
error_log /var/log/nginx/error.log debug;
root /some/www/folder;

location /path {

root /another/www/folder;
rewrite /path(.*)$ $1 last;



I got a 404 page error when I trying to open local/path/index.html

and logs:
user@local:$ grep "/some/www/folder/" local.error.log

2016/10/18 12:55:44 [debug] 602#602: *4 http filename: "/some/www/folder/index.html"
2016/10/18 12:55:44 [error] 602#602: *4 open() "/some/www/folder/index.html" failed (2: No such file or directory), client:, server: local, request: "GET /path/index.html HTTP/1.1", host: "local"

Change History (1)

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

Resolution: invalid
Status: newclosed

According to the documentation of the rewrite directive:

the last parameter stops processing the current set of ngx_http_rewrite_module directives and starts a search for a new location matching the changed URI;

The changed URI in your case is /index.html, and it doesn't match the /path location.

Note: See TracTickets for help on using tickets.