zoukankan      html  css  js  c++  java
  • Nginx -- proxy_pass配置

    一、proxy_pass

      作用域: location

    • 不影响浏览器地址栏的url
    • 设置被代理server的协议和地址
    • 协议可以为http或https
    • 地址可以为域名或IP

    二、配置规则

      2.1 测试环境

      测试机: 172.16.200.160  my.yemao.com

            172.16.200.143 test.yemao.com

      

      注:在proxy_pass中的代理url后加上/,代理转发的url中就不会带上location中匹配路径;

    如果后面没有/,代理转发的url中就会带上location中的匹配路径

      2.2 url 后带 / (则不会加上location中的匹配路径)

      

      

      我们访问 http://my.yemao.com/proxy/index.html,其实是访问到了 http://test.yemao.com/index.html

       2.3 url中不带 / (则会加上location中的匹配路径)

      

           

      我们访问 http://my.yemao.com/proxy/index.html

      其实是访问到了 http://test.yemao.com/proxy/index.html
      这里将 location 中匹配的 proxy 也自动加到了 代理转发的地址后面

       2.4 代理转发的地址后面带目录和/

      

       

      我们访问 http://my.yemao.com/proxy/index.html
      其实是访问到了 http://test.yemao.com/yemao/index.html

      2.5 代理转发的地址后面带目录没有 /

      

       

      我们访问 http://my.yemao.com/proxy/index.html
      其实是访问到了 http://test.yemao.com/testindex.html

      2.6 转发的后台有多个服务器

    upstream backend {
        server backend1.example.com       weight=5;
        server backend2.example.com:8080;
        server unix:/tmp/backend3;
     
        server backup1.example.com:8080   backup;
        server backup2.example.com:8080   backup;
    }
     
    server {
        location / {
            proxy_pass http://backend/user/pub/api/;
        }
    }
    

      

  • 相关阅读:
    初认识AngularJS
    (imcomplete) UVa 10127 Ones
    UVa 10061 How many zero's and how many digits?
    UVa 11728 Alternate Task
    UVa 11490 Just Another Problem
    UVa 10673 Play with Floor and Ceil
    JSON对象和字符串的收发(JS客户端用typeof()进行判断非常重要)
    HTML.ActionLink 和 Url.Action 的区别
    EASYUI TREE得到当前节点数据的GETDATA方法
    jqueery easyui tree把已选中的节点数据拼成json或者数组(非常重要)
  • 原文地址:https://www.cnblogs.com/bigberg/p/7651197.html
Copyright © 2011-2022 走看看