Nginx负载均衡器sticky ip_hash

xfyts7mz  于 2023-05-06  发布在  Nginx
关注(0)|答案(1)|浏览(238)

我试图在nginx负载均衡器中创建粘性,使用我在python应用程序上创建的现有cookie internal_ip。我使用ip_hash方法,因为我没有nginx plus。我是新手,我得到了这个错误:
2023/04/30 16:41:26 [emerg] 1#1:/etc/nginx/nginx.conf中的“ip_hash”指令中的参数数无效:7 nginx:[emerg]/etc/nginx/nginx.conf中的“ip_hash”指令中的参数数无效:7
所以我不明白发生了什么,我的错误在哪里?

events {
worker_connections 1000;
}

http {
    upstream app {
        ip_hash $cookie_internal_ip consistent;
        server 172.18.0.3:5000;
        server 172.18.0.4:5000;
        server 172.18.0.5:5000;
    }

server {
    listen 80;
    location / {
        proxy_pass http://app;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        add_header Set-Cookie "internal_ip=$remote_addr";
    }
}

}

06odsfpq

06odsfpq1#

我也是nginx的新手
1.基于ip_hash文档,它必须是没有任何参数的ip_hash;指令。
1.你是说hash吗?

events {
worker_connections 1000;
}

http {
    upstream app {
        # if you need simply ip sticky load balancing
        ip_hash;
        # if you need hash by key-value sticky load balancing
        hash $cookie_internal_ip consistent;
        server 172.18.0.3:5000;
        server 172.18.0.4:5000;
        server 172.18.0.5:5000;
    }

server {
    listen 80;
    location / {
        proxy_pass http://app;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        add_header Set-Cookie "internal_ip=$remote_addr";
    }
}

相关问题