Maxim Dounin Wrote:
-------------------------------------------------------
Hello again!
> .... and $backend won't be set as a result.
> Moving "set" before
> "rewrite .. break" will do the trick.
Right, in this case the $backend applies to proxy_pass and the request gets proxied but unfortunatelly in this case the rewrite rule does not have effect anymore. It still gets applied according to the error logs, but instead of the rewritten URL path to original one gets proxied. To make it more clear I changed the example configuration I posted above by having each virtual host its own access and error log.
When I run following test ...
$ curl -s -o - -D - http://localhost:92/foo/
HTTP/1.1 404 Not Found
Server: nginx
Date: Wed, 28 Sep 2011 19:26:04 GMT
Content-Type: text/html
Connection: keep-alive
Content-Length: 162
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
I will get this in the error logs
# tail -F /var/log/nginx/{access,error}9[012].log
==> /var/log/nginx/access90.log <==
127.0.0.1 - - [28/Sep/2011:21:26:04 +0200] "GET /foo/ HTTP/1.0" 404 162 "-" "curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5"
==> /var/log/nginx/access92.log <==
127.0.0.1 - - [28/Sep/2011:21:26:04 +0200] "GET /foo/ HTTP/1.1" 404 162 "-" "curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5"
==> /var/log/nginx/error90.log <==
2011/09/28 21:26:04 [error] 3078#0: *15 "/usr/share/nginx/html/foo/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: _, request: "GET /foo/ HTTP/1.0", host: "localhost:90"
==> /var/log/nginx/error92.log <==
2011/09/28 21:26:04 [notice] 3078#0: *13 "^/foo/(.*)$" matches "/foo/", client: 127.0.0.1, server: _, request: "GET /foo/ HTTP/1.1", host: "localhost:92"
2011/09/28 21:26:04 [notice] 3078#0: *13 rewritten data: "/", args: "", client: 127.0.0.1, server: _, request: "GET /foo/ HTTP/1.1", host: "localhost:92"
2011/09/28 21:26:04 [notice] 3078#0: *13 "^/foo/(.*)$" does not match "/", client: 127.0.0.1, server: _, request: "GET /foo/ HTTP/1.1", host: "localhost:92"
2011/09/28 21:26:04 [info] 3078#0: *13 client 127.0.0.1 closed keepalive connection
If this in not what you would expect, I can rebuild Nginx with --with-debug tomorrow and repeat the test.