Load balancing of PHP server with upstream module in Nginx

Source: Internet
Author: User
Tags php server nginx server nginx load balancing

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.