CentOS 6.5 + nginx 1.8.0 + PHP 5.6 (with PHP-FPM) load balanced source installation (c) Nginx load balancer Configuration

Source: Internet
Author: User
Tags nginx server nginx reverse proxy

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

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.