Skylar Saveland
Skylar Saveland

Reputation: 11464

Nginx location, alias, rewrite, root

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/;
    }

Upvotes: 4

Views: 21047

Answers (3)

user225324
user225324

Reputation:

You can:

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

then use this config:

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

Upvotes: 1

Martin Redmond
Martin Redmond

Reputation: 13986

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.

Upvotes: 1

Matt Saunders
Matt Saunders

Reputation: 29

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

Upvotes: 2

Related Questions