views:

1803

answers:

3

I'm serving /foo/bar/ by way of proxypass and want to continue doing so. However, I would like to serve /foo/bar/baz.swf statically from say /var/www/mystatic/baz.swf and so forth.

I was hoping that I could do something like

    location /foo/bar/(.*) {
      alias /var/www/mystatic/;
    }

    location / {
      proxy_pass ....;
      ... 
    }

And /foo/bar/ would go to the application server while /foo/bar/(.*) would be served statically.

the docs say that I can't do this and need to use a combination of root and rewrite: http://wiki.nginx.org/NginxHttpCoreModule

Adding to the complication, I would like to continue using the ancient, unsupported 0.5.33. Any help would b greatly appreciated.

Edit: moving forward, someone suggested using root instead of alias. But, it doesn't seem that I can use any regex on the location directive with my version? Here, /foo/bar/baz.swf is served by the proxy_pass! I have the file at /var/www/foo/bar/baz.swf.

    location /foo/bar/(.+) {
      root /var/www/;
    }
A: 

You can do this; but it's slightly esoteric. Try using:

location ^~ /foo/bar {
    alias /var/www/mystatic/;
}

location / {
    proxy_pass ....;
}

These options are documented on the Wiki http://wiki.nginx.org/NginxHttpCoreModule#location

Matt Saunders
If I do that /foo/bar/ is served by nginx .. if I add the trailing slash ... I still don't correctly line up /foo/bar/baz.js
skyl
A: 
location = /foo/bar/baz.swf {}

will clear clear any options set to /foo/bar/baz.swf. So you can leave it where it is as the proxy options will not be used.

Martin Redmond
A: 

You can:

# mkdir /var/www/foo  
# mv /var/www/mystatic /var/www/foo/bar

then use this config:

location ~ ^/foo/bar/(.+) {
  root /var/www/;
}
azuwis