« »
2010-12-07Nginx

165

Nginx:proxy_pass路径问题解决方案

在nginx中配置proxy_pass时,如果是按照^~匹配路径时,要注意proxy_pass后的url最后的/

当加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走
如果没有/,则会把匹配的路径部分也给代理走

location ^~ /blog/
{
    proxy_cache blog_cache;
    proxy_set_header Host blog.linuxany.com;
    proxy_pass http://blog.linuxany.com/;
}

如果请求的url是http://www.linuxany.com/blog/test.html
会被代理成http://blog.linuxany.com/test.html

而下面的配置

location ^~ /blog/
{
   proxy_cache blog_cache;
   proxy_set_header Host blog.linuxany.com
   proxy_pass http://blog.linuxany.com;
}

则会被代理到http://blog.linuxany.com/blog/test.htm

您还可能感兴趣的内容

日志信息 »

该日志于2010-12-07 12:48由 admin 发表在Nginx分类下, 你可以发表评论。除了可以将这个日志以保留源地址及作者的情况下引用到你的网站或博客,还可以通过RSS 2.0订阅这个日志的所有评论。

没有评论

发表评论 »


返回顶部