nginx - 如何在nginx中测试负载平衡?

标签 nginx

我在 nginx 中完成了重定向配置,并且成功运行。
但我想要负载平衡:-
为此,我已经创建了 负载平衡器.conf 以及在该文件中提供服务器名称,例如:-

upstream backend {
  # ip_hash;

   server 1.2.3.4;
   server 5.6.7.8;
 }

server {
   listen 80;

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

在这两种情况下,我都做了相同的配置
并且它默认使用循环算法,因此在该请求中通过一台电脑传输到另一台电脑.....
但它不起作用

任何人都可以向我建议任何 secong 请求转到另一台服务器 5.6.7.8

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

非常感谢。

最佳答案

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

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;
   }
}

然后检查您的日志文件
须藤猫/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 - 如何在nginx中测试负载平衡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40859396/

相关文章:

nginx - 为什么 Nginx 会从默认目录而不是新目录正确地提供文件?

ubuntu - Nginx密码认证排除一个目录

docker - 如何在 nginx 代理中添加 api key 身份验证?

Nginx $ request_uri具有重复的查询参数

Nginx - 如何在使用 try_files 时为 index.html 添加标题

php - Nginx - 在其他目录和 PHP 中具有 root 的位置

docker - 使用 php7.1、laravel 和 nginx 服务器设置 docker,出现 Bad Gateway 502 异常

uwsgi 中的 nginx 负载均衡

php - 在 Vagrant 中使用 XDEBUG

node.js - 使用 xhr-polling 时 Socket.io 的服务器响应时间过长