Nginx的位置,别名,重写,根 [英] Nginx location, alias, rewrite, root

查看:223
本文介绍了Nginx的位置,别名,重写,根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在服务/ foo / bar /通过proxypass,并希望继续这样做。但是,我想从/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而不是别名。但是,似乎我可以使用我的版本的位置指令上的任何正则表达式?这里,/foo/bar/baz.swf由proxy_pass提供!我有文件在/var/www/foo/bar/baz.swf。

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


解决方案

但它有点深奥。尝试使用:

 位置^〜/ foo / bar {
alias / var / www / mystatic /;
}

location / {
proxy_pass ....;
}

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


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

解决方案

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

这篇关于Nginx的位置,别名,重写,根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆