我在 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/