| |
    今天用nginx作为trac的反代,发现一个问题,就是登入登出跳转的时候是白页,看了下网页相应内容,发现相应的location是空的。查了一下发现是只单纯用了proxy_pass,没有使用proxy_redirect.
    假设前端url是example.com。后端server域名是in.com,那么后端server在返回refresh或location的时候,host为in.com,显然这个信息直接返回给客户端是不行的,需要nginx做转换,这时可以设置:
    proxy_redirect http://in.com  /
    nginx会将host及port部分替换成自身的server_name及listen port。不过这种配置对server_name有多个值的情况下支持不好。
我们可以用nginx内部变量来解决这一问题:
    proxy_redirect http://in.com http://$host:$server_port


    搞定

    如果不设定的话,proxy_redirect默认是default属性,官网例子是这样介绍default的:
引用
location /one/ {
  proxy_pass       http://upstream:port/two/;
  proxy_redirect   default;
}

location /one/ {
  proxy_pass       http://upstream:port/two/;
  proxy_redirect   http://upstream:port/two/   /one/;
}


  
    我试了下,location /{}规则时似乎不太正常,会导致location为空。这个有待详细考证
by snooda | 分类: 默认分类 | 评论(4) | 引用(0) | 阅读(41811)
哈哈
2017/03/14 15:48
zan
erteterter
2015/11/04 09:48
新手学习了
丰富 Homepage
2014/10/31 22:32
学习了
jdwx Email Homepage
2013/01/29 11:44
Nginx虽小但功能完善,高效率。
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]