4

我正在通过 proxypass 服务 /foo/bar/ 并希望继续这样做。但是,我想从 /var/www/mystatic/baz.swf 等静态地服务 /foo/bar/baz.swf 等等。

我希望我能做类似的事情

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

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

/foo/bar/ 将转到应用程序服务器,而 /foo/bar/(.*) 将静态提供。

文档说我不能这样做,需要结合使用 root 和重写:http ://wiki.nginx.org/NginxHttpCoreModule

更复杂的是,我想继续使用古老的、不受支持的 0.5.33。任何帮助将不胜感激。

编辑:继续前进,有人建议使用 root 而不是别名。但是,我的版本似乎不能在 location 指令上使用任何正则表达式?在这里,/foo/bar/baz.swf 由 proxy_pass 提供服务!我的文件位于 /var/www/foo/bar/baz.swf。

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

3 回答 3

2

你可以这样做; 但它有点深奥。尝试使用:

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

location / {
    proxy_pass ....;
}

这些选项记录在 Wiki http://wiki.nginx.org/NginxHttpCoreModule#location

于 2009-12-01T00:02:34.853 回答
1
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.

于 2009-12-03T04:46:47.190 回答
1

你可以:

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

然后使用这个配置:

location ~ ^/foo/bar/(.+) {
  root /var/www/;
}
于 2009-12-05T08:29:11.340 回答