Nginx Load Balancing

Source: Internet
Author: User
Tags nginx load balancing

Nginx Load Balancing

Understanding of Nginx Load Balancing

Nginx is a lightweight, high-performance webserver, he can mainly do the following two things:

As an HTTP server (as with Apache)
Load balancing as a reverse proxy server

Now Nginx everywhere can be seen, often see the page after the outage will show Nginx words, which also shows that nginx because of high performance, use configuration simple, open source single These features are more and more users accept, used.

One of the first as an HTTP server, combined with the PHP-FPM process, the request sent to the processing, nginx itself will not parse PHP, he just as a server, accept the request from the client, if it is a PHP request, then to the PHP process processing, and send the results of PHP processing to the client. This is very simple, install the NGINX+PHP-FPM after the configuration of the respective configuration file, start can be achieved. The principle of operation can be seen in the following paragraph explanation:

Nginx does not support direct invocation or parsing of external programs, and all external programs (including PHP) must be called through the FastCGI interface. The FastCGI interface is a socket under Linux (the socket can be either a file socket or an IP socket). In order to invoke a CGI program, you also need a fastcgi wrapper (wrapper can be understood as the program used to start another program), which is bound to a fixed socket, such as a port or a file socket. When Nginx sends the CGI request to the socket, through the FastCGI interface, the wrapper receives the request, and then derives a new thread, which invokes the interpreter or the external program to process the script and reads the return data; The wrapper then passes the returned data through the FastCGI interface, passing it to nginx along a fixed socket, and finally, Nginx sends the returned data to the client. This is the whole process of nginx+fastcgi, as shown.

Reverse proxy is the opposite of the proxy (or proxy), you have to listen to the proxy, in order to more convenient access to B resources, through a resource indirect access to B resources, the characteristics of users know what the final site to visit is what, but the reverse proxy users do not know what to do behind the proxy server, Reverse proxy in the service of the real processing server in the intranet, the external network can only access the reverse proxy server, which greatly improves security.


Simple configuration:

Add the following code to the HTTP segment

Upstream A.com {
Server 192.168.5.126:80;
Server 192.168.5.27:80;
}

server{
Listen 80;
server_name a.com;
Location/{
Proxy_pass http://a.com;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}
}

Nginx Load Balancing

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.