Fork me on GitHub

nginx与php-fpm的负载均衡


你不必跑在任何人后边。

Nginx反向代理负载均衡架构图(三台服务器为例)

Nginx负载均衡(图示:192.168.1.1:80服务器配置)

upstream示例配置

1
2
3
4
5
upstream icontact_pool {
server 192.168.1.1:9000 weight=5 max_fails=3 fail_timeout=20s;
server 192.168.1.2:9000 weight=3 max_fails=3 fail_timeout=20s;
server 192.168.1.3:9000 weight=2 max_fails=3 fail_timeout=20s;
}

ngxin虚拟主机负载均衡配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
server {
listen 192.168.1.1:80;
server_name 192.168.1.1;
access_log /var/log/nginx/balance/loadbalance.access.log;
error_log /var/log/nginx/balance/loadbalance.error.log;
#允许列目录
location / {
root /balance/;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
allow allow;
}
#proxy the php scripts to fpm_pool_upstream
location ~ \.php$ {
root /balance;
include /etc/nginx/fastcgi_params;
#将webserver接收的客户端请求通过fastcgi负载均衡到php5-fpm的池
fastcgi_pass icontact_pool;
}
}

负载均衡服务器处理php请求

192.168.1.1:9000、192.168.1.2:9000、192.168.1.3:9000为后端的三台负载均衡服务器监听的fpm地址和端口号,负载均衡服务器通过fastcgi将http请求和上下文参数发送给这个fpm池,然后fpm负责解析php程序

https://blog.csdn.net/wzy_1988/article/details/8230562

请我喝一个苹果味的美年达吧,谢谢!