Nginx-反向代理

  1. 关键词匹配
  2. 域名转发
  3. 转发到多台

关键词匹配

location ~ ^/TEST/ {
    rewrite     /TEST/(.*)$ /$1 break;
    proxy_next_upstream http_502 http_504 error timeout invalid_header;
    proxy_set_header Host  $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_pass http://ip:port;
    expires     3d;
}

域名转发

server {
   listen     80;
   server_name 域名;
   location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header Host $http_host;
      proxy_set_header REMOTE-HOST $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_pass http://ip:port;
   }
}

转发到多台

upstream baidunode {
   server xxx:port weight=10 max_fails=3  fail_timeout=30s;
   server xxx:port weight=10 max_fails=3  fail_timeout=30s;
}
location / {
   add_header Cache-Control no-cache;
   proxy_set_header   Host local.baidu.com;
   proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
   proxy_set_header   X-Real-IP        $remote_addr;
   proxy_pass         http://baidunode;
   proxy_connect_timeout 30s;
}

转载请注明来源,欢迎指出任何有错误或不够清晰的表达。

文章标题:Nginx-反向代理

文章字数:119

本文作者:猿码记

发布时间:2017-04-17 12:32

原始链接:liuqh.icu/2017/04/17/Nginx-反向代理/

版权声明: 转载请保留原文链接及作者。

目录
×

看您心情~~