首页 > 编程知识 正文

nginx负载均衡调度策略,nginx负载均衡策略配置

时间:2023-05-06 07:23:40 阅读:280264 作者:3845

配置基于客户端ip_hash的负载均衡

$ vim $NGINX_HOME/conf/nginx.confworker_processes auto;events { use epoll; worker_connections 65535;}http { upstream aidan.org{ ip_hash; server 127.0.0.1:8881; server 127.0.0.1:8882; server 127.0.0.1:8883; } server { listen 80; server_name aidan.org; location / { proxy_pass http://aidan.org; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } }}$ nginx -s reload

测试一下ip_has的效果

[root@localhost ~]# curl aidan.orghello nginx,I'm 8883 Server.nginx host is aidan.org,your realIp is 127.0.0.1[root@localhost ~]# curl aidan.orghello nginx,I'm 8883 Server.nginx host is aidan.org,your realIp is 127.0.0.1[root@localhost ~]# curl aidan.orghello nginx,I'm 8883 Server.nginx host is aidan.org,your realIp is 127.0.0.1

发现都是同一个服务在提供服务

小结

ip哈希负载均衡使用ip_hash指定定义;
nginx使用客户端的IP地址进行哈希计算,确保使用同一个服务器响应请求;

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。