Nginx reverse proxy to a single php-fpm (PHP-FPM can be located on different machines)
0. First, create our website root directory "NOTE: The machine where the PHP-FPM is located" (after the code of the site is placed in this directory):
Mkdir/opt/www
1. Edit Nginx configuration file
VI /usr/local/nginx/conf/nginx.conf
Modify under the server block (37 rows):
# Add this line, which represents the root directory of the Web site that accesses this server
Modify the location/segment in which the default Access file is supported by adding. php Files:
Location/ { #root /opt/www; #注释掉此行 index index. PHP index.html index. htm;}
The next configuration is to ensure that requests for. php files will be routed to the backend PHP-FPM module, uncomment the default PHP configuration block, and modify the following:
Location ~ \. php$ { #root index; #注释掉此行
Fastcgi_pass 192.168.168.132:9000; #此为后端PHP-FPM's intranet IP address fastcgi_index index. PHP; Fastcgi_param script_filename $doccument _root$fastcgi _script_name; #此行被修改 include fastcgi_params;}
Save the configuration.
After changing the configuration, we need to restart the Nginx server, or reload (only let it reload the configuration), so that the changes take effect:
Service Nginx Reload
Below we create a test code that tests whether the access is normal "Note: Must be created in the machine where the PHP-FPM is located":
cd/opt/wwwvi index. php
Write the following code:
<? PHP Echo ' Hello! I am server-b ';
Then use the browser of other computers to access the ip:http://192.168.168.131 of the machine where Nginx is located, and get the following results:
Load balancing of Nginx and PHP-FPM cluster
1.
CentOS 6.5 + nginx 1.8.0 + PHP 5.6 (with PHP-FPM) load balanced source installation (c) Nginx load balancer Configuration