A correction to my earlier post: the request in my first question above should be for "mysite.com/foo/bar/sth/sth.html", and there is a corresponding file on the filesystem: "/home/www/mysite/static/foo/bar/sth/sth.html".
Just tried something different, with this config:
root /home/www/mysite/static;
location /foo/bar/ {
internal;
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
}
request to "mysite.com/foo/bar/sth" will return 404, and I can see that the request does not even get proxied to the application server. In addition, this access is not logged in error log but in the access log of nginx. However, request to "mysite.com/foo/bar/sth/sth.html" is served fine, despite of using "internal" directive.