Just turned on rewrite log and debug log and found out that your problem is in rewriting to -
. Unlike Apache, nginx takes it literally and rewrite request URI to string -
. Then it cannot find any location
block that matches this URI and uses it's magic configuration ""
that just happens to have all the server rewrite
rules. So new URI goes through all the rewrite rules again.
Here is the log:
2016/06/01 19:52:41 [debug] 7288#7288: *24 http header: "Host: example.com"
2016/06/01 19:52:41 [debug] 7288#7288: *24 http header: "User-Agent: curl/7.47.0"
2016/06/01 19:52:41 [debug] 7288#7288: *24 http header: "Accept: */*"
2016/06/01 19:52:41 [debug] 7288#7288: *24 http header done
2016/06/01 19:52:41 [debug] 7288#7288: *24 event timer del: 4: 1464800021049
2016/06/01 19:52:41 [debug] 7288#7288: *24 generic phase: 0
2016/06/01 19:52:41 [debug] 7288#7288: *24 rewrite phase: 1
2016/06/01 19:52:41 [debug] 7288#7288: *24 http script regex: "^/css/"
2016/06/01 19:52:41 [notice] 7288#7288: *24 "^/css/" matches "/css/asd", client: 127.0.0.1, server: example.com, request: "GET /css/asd HTTP/1.1", host: "example.com"
2016/06/01 19:52:41 [debug] 7288#7288: *24 http script copy: "-"
2016/06/01 19:52:41 [debug] 7288#7288: *24 http script regex end
2016/06/01 19:52:41 [notice] 7288#7288: *24 rewritten data: "-", args: "", client: 127.0.0.1, server: example.com, request: "GET /css/asd HTTP/1.1", host: "example.com"
2016/06/01 19:52:41 [debug] 7288#7288: *24 test location: "/"
2016/06/01 19:52:41 [debug] 7288#7288: *24 using configuration ""
2016/06/01 19:52:41 [debug] 7288#7288: *24 http cl:-1 max:1048576
2016/06/01 19:52:41 [debug] 7288#7288: *24 rewrite phase: 3
2016/06/01 19:52:41 [debug] 7288#7288: *24 rewrite phase: 4
2016/06/01 19:52:41 [debug] 7288#7288: *24 http script regex: "^/css/"
2016/06/01 19:52:41 [notice] 7288#7288: *24 "^/css/" does not match "-", client: 127.0.0.1, server: example.com, request: "GET /css/asd HTTP/1.1", host: "example.com"
2016/06/01 19:52:41 [debug] 7288#7288: *24 http script regex: "^/$"
2016/06/01 19:52:41 [notice] 7288#7288: *24 "^/$" does not match "-", client: 127.0.0.1, server: example.com, request: "GET /css/asd HTTP/1.1", host: "example.com"
2016/06/01 19:52:41 [debug] 7288#7288: *24 http script regex: "^"
2016/06/01 19:52:41 [notice] 7288#7288: *24 "^" matches "-", client: 127.0.0.1, server: example.com, request: "GET /css/asd HTTP/1.1", host: "example.com"
2016/06/01 19:52:41 [debug] 7288#7288: *24 http script copy: "/"
2016/06/01 19:52:41 [debug] 7288#7288: *24 http script regex end
2016/06/01 19:52:41 [notice] 7288#7288: *24 rewritten redirect: "/", client: 127.0.0.1, server: example.com, request: "GET /css/asd HTTP/1.1", host: "example.com"
Fix to initial problem could be as simple as:
rewrite ^(/(css|img|js)/.+) $1 break;
or
rewrite ^/(css|img|js)/ $uri break;
So, you should care to what you rewrite your URI.
break
flag and why it doesn't seem to work.-
in rewrite.-
means I don't care what it's rewritten to, I just want to stop processing the rules. Is that my mistake here? Maybe you could post an answer if you think you know how to getbreak
to work.