首页 > 其他 > 详细

nginx 设置来源IP固定请求后端接口

时间:2019-12-31 16:20:56      阅读:165      评论:0      收藏:0      [点我收藏+]

nginx 配置 设置IP请求到固定后端接口

nginx 配置示例:

server {
    listen   80;
    access_log   /var/log/nginx/access.log;
 
    location / {
        proxy_ignore_client_abort on;
        proxy_read_timeout 200s;
        proxy_redirect    off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto  $scheme;
        client_max_body_size    1000m;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
 
        if ($remote_addr ~ "172.16.2.53")
        {
            proxy_pass    http://client3;
            break;
        }
 
        if ($remote_addr ~ "172.16.2.54")
        {
            proxy_pass    http://client4;
            break;
        }
 
        proxy_pass    http://client5;
    }
}
upstream client3 {
    server 172.16.2.53:8080 max_fails=5 fail_timeout=10;
}
 
upstream client4 {
    server 172.16.2.54:8080 max_fails=5 fail_timeout=10;
}
 
upstream client5 {
    server 172.16.2.55:8080 max_fails=5 fail_timeout=10;
}

nginx 设置来源IP固定请求后端接口

原文:https://www.cnblogs.com/sharesdk/p/12124863.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!