如何在Nginx中测试负载平衡? [英] How to test load balancing in nginx?

查看:87
本文介绍了如何在Nginx中测试负载平衡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在nginx中完成了重定向配置,它成功运行. 但是在那我想要负载平衡:- 为此,我已经创建了 load-balancer.conf ,并将服务器名称输入该文件,例如:-

I done congfiguration in nginx for redirection and it works successfully. But in that i want load balancing :- for that i already create load-balancer.conf as well as give server name into that file like :-

upstream backend {
  # ip_hash;

   server 1.2.3.4;
   server 5.6.7.8;
 }

server {
   listen 80;

   location / {
      proxy_pass http://backend;
   }
}

在两种情况下,我都进行了相同的配置 它默认使用循环算法,因此请求通过一台PC传输到另一台PC ... 但是没有用

In both instances i did same configuration and it default uses round-robin algorithm so in that request transfer via one pc to another pc..... but it were not working

任何人都可以向我建议任何要求转到另一台服务器5.6.7.8的内容

can any one suggest me anything that secong request going to another server 5.6.7.8

所以我可以检查负载平衡.

so i can check load balancing.

非常感谢.

推荐答案

为上游创建日志文件,以检查请求将发送到哪个服务器

Create a log file for upstream to check request is going to which server

http {
   log_format upstreamlog '$server_name to: $upstream_addr {$request} '
   'upstream_response_time $upstream_response_time'
   ' request_time $request_time';

upstream backend {
  # ip_hash;

   server 1.2.3.4;
   server 5.6.7.8;
 }

server {
   listen 80;
   access_log /var/log/nginx/nginx-access.log upstreamlog;
   location / {
      proxy_pass http://backend;
   }
}

,然后检查您的日志文件 sudo cat/var/log/nginx/nginx-access.log;

and then check your log file sudo cat /var/log/nginx/nginx-access.log;

您将看到类似的日志

to: 5.6.7.8:80 {GET /sites/default/files/abc.png HTTP/1.1} upstream_response_time 0.171 request_time 0.171

这篇关于如何在Nginx中测试负载平衡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆