zoukankan      html  css  js  c++  java
  • nginx配置中proxy_redirect的作用(转)

    nginx配置中proxy_redirect的作用(转)

    来自http://wntest.ustc.edu.cn/mine/wordpress/?p=400 
    及 http://hi.baidu.com/171892549/blog/item/0ec6aaef22acbb1dfdfa3ca7.html 


    NGINX的proxy_redirect功能比较强大,其作用是对发送给客户端的URL进行修改。以例子说明: 


       server { 
           listen       80; 
           server_name  test.abc.com; 
           location / { 
                proxy_pass http://10.10.10.1:9080; 
           } 
       }这段配置一般情况下都正常,但偶尔会出错, 错误在什么地方呢? 抓包发现服务器给客户端的跳转指令里加了端口号,如 Location: http://test.abc.com:9080/abc.html 。因为nginx服务器侦听的是80端口,所以这样的URL给了客户端,必然会出错.针对这种情况, 加一条proxy_redirect指令: proxy_redirect http://test.abc.com:9080/ / ,把所有“http://test.abc.com:9080/”的内容替换成“/”再发给客户端,就解决了。 


       server { 
           listen       80; 
           server_name  test.abc.com; 
           proxy_redirect http://test.abc.com:9080/ /; 
           location / { 
                proxy_pass http://10.10.10.1:9080; 
           } 
       } 




    http://nginx.179401.cn/ 
    圣地啊 加红 加粗~!! 




    出处:http://nginx.179401.cn/StandardHTTPModules/HTTPProxy.html 
    proxy_redirect 
    语法:proxy_redirect [ default|off|redirect replacement ] 
    默认值:proxy_redirect default 
    使用字段:http, server, location 
    如果需要修改从被代理服务器传来的应答头中的"Location"和"Refresh"字段,可以用这个指令设置。 
    假设被代理服务器返回Location字段为: http://localhost:8000/two/some/uri/ 
    这个指令: 
    proxy_redirect http://localhost:8000/two/ http://frontend/one/; 
    将Location字段重写为http://frontend/one/some/uri/。 
    在代替的字段中可以不写服务器名: 


    proxy_redirect http://localhost:8000/two/ /; 
    这样就使用服务器的基本名称和端口,即使它来自非80端口。 
    如果使用“default”参数,将根据location和proxy_pass参数的设置来决定。 
    例如下列两个配置等效: 


    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/;} 
    在指令中可以使用一些变量: 


    proxy_redirect   http://localhost:8000/    http://$host:$server_port/; 
    这个指令有时可以重复: 


    proxy_redirect   default;  proxy_redirect   http://localhost:8000/    /;  proxy_redirect   http://www.example.com/   /; 
    参数off将在这个字段中禁止所有的proxy_redirect指令: 


    proxy_redirect   off;  proxy_redirect   default;  proxy_redirect   http://localhost:8000/    /;  proxy_redirect   http://www.example.com/   /; 
    利用这个指令可以为被代理服务器发出的相对重定向增加主机名:
  • 相关阅读:
    Python 学习笔记 11.模块(Module)
    Python 学习笔记 8.引用(Reference)
    Python 学习笔记 9.函数(Function)
    Python 学习笔记 6.List和Tuple
    Python 学习笔记 4.if 表达式
    Python 学习笔记 2.自省
    Python 学习笔记 3.简单类型
    Python 学习笔记 7.Dictionary
    Python 学习笔记 5.对象驻留
    Python 学习笔记 10.类(Class)
  • 原文地址:https://www.cnblogs.com/fengff/p/12557790.html
Copyright © 2011-2022 走看看