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

      

  • 相关阅读:
    #研发解决方案介绍#基于持久化配置中心的业务降级
    #研发解决方案介绍#Tracing(鹰眼)
    #研发解决方案介绍#Recsys-Evaluate(推荐评测)
    穷追不舍、事故入手和倒逼
    职场的真相——七句话
    被小伙伴们吓哭了:可怕的命令
    适用于研发基层员工的十个行为模式
    研发阿米巴组织的运行逻辑
    技术总监是干什么的?
    大学教给了我们什么(二)
  • 原文地址:https://www.cnblogs.com/bigberg/p/7651197.html
Copyright © 2011-2022 走看看