• nginx location proxy pass


    nginx:
    192.168.1.23作为nginx反向代理机器
    目标机器192.168.1.5上部署一个8090端口的nginx
    
    [root@localhost conf.d]# cat test.conf
    server {
    listen 80;
    server_name localhost;
    location / {
    root /var/www/html;
    index index.html;
    }
     
    location  /proxy/ {
              proxy_pass http://192.168.1.5:8090/;
    }
    }
    
    访问http://192.168.1.23/proxy/就会被代理到http://192.168.1.5:8090/, 浏览器的url是http://192.168.1.23/proxy/不变,
    目标机器上无需存在proxy目录(curl http://192.168.1.23/proxy 可以发现是302,301重定向)
    
    
    如果:proxy_pass配置的url后面不加"/"
    [root@localhost conf.d]# cat test.conf
    server {
    listen 80;
    server_name localhost;
    location / {
    root /var/www/html;
    index index.html;
    }
     
    location  /proxy/ {
              proxy_pass http://192.168.1.5:8090;
    }
    }
    
    那么访问http://192.168.1.23/proxy或http://192.168.1.23/proxy/,都会失败!
    这样配置后,访问http://192.168.1.23/proxy/就会被反向代理到http://192.168.1.5:8090/proxy/,目标机必须有proxy目录 

    快速记忆:proxypass最后如果带 / ,则代理到目标机就没有location后面的目录,  不带 /  , 到目标机后携带location后面的目录,一起带过去了

  • 相关阅读:
    startup毕业论文
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
    install
    逻辑卷(lv)管理(LVM)
    mke2fs
    cat & 文件结束符
  • 原文地址:https://www.cnblogs.com/yum777/p/9691433.html
Copyright © 2020-2023  润新知