Use nginx to configure multiple PHP FastCGI Server Load balancer instances

Source: Internet
Author: User
Tags what php nginx server

The front-end of an application is an nginx server. All static content is processed by nginx, all PHP requests are distributed to several downstream servers running the PHP FastCGI daemon. In this way, the system load can be apportioned in a cheap way, expand the load capacity of the system.
The IP addresses of the three PHP FastCGI servers are:
172.16.236.110, 172.16.236.111, 172.16.236.112
When running the PHP FastCGI process, you need to let PHP-CGI listen to the server's LAN address (as shown above), instead of the local address (127.0.0.1) that was previously listened ). Take 172.16.236.110 as an example:
/Usr/local/PhP5/bin/PHP-CGI-B 172.16.236.110: 9000
Maybe you can use spawn-fcgi to start PHP-fcgi (for your reference, you can modify the listening address and port ):
/Usr/local/Lighttpd/bin/spawn-fcgi-F/usr/local/PhP5/bin/PHP-CGI-A 172.16.236.110-P 9000
Maybe you are using PHP-FPM to manage PHP-fcgi, then you need to modify the PHP-FPM configuration: VI/usr/local/PhP5/etc/php-fpm.conf
Find this configuration item (the address may need to be adjusted according to your environment)
<Value name = "listen_address"> 127.0.0.1: 9000 </value>
To:
<Value name = "listen_address"> 172.16.236.110: 9000 </value>
After modification, restart your PHP-FPM process.
Then, follow the steps above to modify other PHP FastCGI servers in sequence.
This is what PHP does for the time being. Modify nginx below.
VI/usr/local/nginx/CONF/nginx. conf
Add a configuration similar to the following in the HTTP segment of the configuration file:
Upstream myfastcgi {
Server 172.16.236.110 Weight = 1;
Server 172.16.236.111 Weight = 1;
Server 172.16.236.112 Weight = 1;
}
The weights of the three PHP FastCGI servers are the same, so the weight value is 1. If your PHP FastCGI server needs to be divided into primary and secondary, you can adjust the weight value to achieve the goal. For example, the first server is the primary server, and the other two servers are the secondary servers:
Upstream myfastcgi {
Server 172.16.236.110 Weight = 1;
Server 172.16.236.111 Weight = 2;
Server 172.16.236.112 Weight = 2;
}
Then find the original nginx section about PhP FastCGI configuration, for example:
Location ~ \. Php $ {
# Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_pass myfastcgi;
# Alternatively, you can reverse proxy to proxy_pass http: // myphpcgi
Fastcgi_index index. php;
Fastcgi_param script_filename $ document_root $ fastcgi_script_name;
Include fastcgi_params;
}
Change the section fastcgi_pass to: fastcgi_pass myfastcgi;
The myfastcgi is the name of the PHP FastCGI balancer configured above.
Restart 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.