NGINX implements PHP requests to other servers

Source: Internet
Author: User
Tags fpm php server nginx server

For example, server A forwards A php request to server B.

Modify server A as follows

The code is as follows: Copy code

Location ~ . Php $ {
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Include fastcgi_params;
}

Change the ip address to the IP address of the PHP server.

The code is as follows: Copy code

Location ~ . Php $ {
Fastcgi_pass 192.168.4.3: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Include fastcgi_params;
}

The following table lists the configurations of the target server (server B, namely, the PHP Server)

First, enable server B's port modification and add a line to/etc/sysconfig/iptables.

The code is as follows: Copy code
-A input-m state -- state NEW-m tcp-p tcp -- dport 9000-j ACCEPT

Configure the php-fpm file
Yum is installed normally in/etc/php-fpm.d/www. conf, which is compiled and installed normally in/usr/local/php/etc/php-fpm.conf

The code is as follows: Copy code

Modify:
Listen = 127.0.0.1: 9000
Change
Listen = 0.0.0.0: 9000

Modify

The code is as follows: Copy code
Listen. allowed_clients = 127.0.0.1
Add allowed servers. In this example, two additional servers are added.
Listen. allowed_clients = 127.0.0.1, 192.168.4.3, 192.168.4.127

You can also comment out the listen. allowed_clients configuration. By default, the listen. allowed_clients configuration allows connections from any machine without IP address restrictions.

Note: The nginx server and the php server should be deployed in the same directory. Otherwise, the File "File not found." will not be found in the 404 error ."

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.