The upstream module in Nginx implements load balancing of PHP server upstream module introduction
Nginx load balancing function relies on the Ngx_http_upstream_module module, the supported proxy methods include Proxy_pass, Fastcgi_pass, Memcached_pass. Upstream is nginx as the core structure of proxy and cache and requests upstream send to downstream can be intervened by the related module.
Test environment
Nginx Server ip:192.168.58.134
PHP Server 1ip:192.168.58.132
PHP Server 2ip:192.168.58.130
Configuring Nginx server with experimental setup
First build Nginx server, in the previous blog, Nginx Server has been set up, here we need to modify the nginx.conf file, in the inside enable upstream module, for the PHP server pool configuration, to achieve its load balance.
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf #gzip on; upstream php { #定义定义php服务器池,权重都为1,相当于访问模式是轮询 server 192.168.58.132:9000 weight=1; server 192.168.58.130:9000 weight=1; } server { listen 80; server_name localhost; location ~ \.php$ { root /var/www/html/webphp; #两台php服务器中都必须要有这个目录,里面有不同的index.php文件 fastcgi_pass php; #这里要修改为php服务器池,而不是单个服务器 fastcgi_index index.php; include fastcgi.conf; }[[email protected] ~]# service nginx stop[[email protected] ~]# service nginx start#重启Nginx服务
Configuring the PHP Server
Two PHP servers are configured as well, and are detailed in the previous blog post. Then all you have to enable PHP-FPM, see boot OK.
Test
We visited 192.168.58.134/index.php to see two PHP servers taking turns to access and finally load balanced.
Load balancing of PHP server with upstream module in Nginx