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

      

  • 相关阅读:
    pip install MySQL-python 失败
    E: Unable to correct problems, you have held broken packages
    git 提交顺序
    git 分支
    ubuntu 安装git
    ubuntu 有些软件中不能输入中文
    ubuntu 完全卸载mysql
    Linux中常用操作命令
    基于注解的Spring AOP的配置和使用
    log4j配置详解
  • 原文地址:https://www.cnblogs.com/bigberg/p/7651197.html
Copyright © 2011-2022 走看看