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

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;
}
原文地址:https://www.cnblogs.com/sharesdk/p/12124863.html