NGINX-load balancing (reverse proxy)

NGINX load balancing

proxy

1. Forward proxy
is what we often call proxy. Its working principle is: I can't access a certain website, but I can access a proxy server. This proxy server can access the website that I cannot access, so I connect The proxy server tells him that I need the content that cannot be accessed on the website, and the proxy server retrieves it and returns it to me. From the perspective of the website, there is only one record when the proxy server fetches the content. Sometimes it is not known that it is the user's request and the user's information is also hidden, depending on whether the proxy tells the website.
In short, the forward proxy is a server located between the client and the origin server. In order to obtain content from the origin server, the client sends a request to the proxy and specifies the target, and then the proxy forwards the request to the origin server and returns the obtained content to Client. The client must make some special settings to use the forward proxy.

2. Reverse proxy A
reverse proxy means that the client does not know that there is no content on the proxy server that it wants. For the client, the proxy server is the original server, and the client does not need to make any special settings. The content in the server's namespace sends ordinary requests, and then the reverse proxy server determines where to forward the request, and returns the obtained content to the client as if the content is his own.

3. The difference between forward proxy and reverse proxy The
typical application of forward proxy is to provide access to the Internet for LAN clients in the firewall.
The forward proxy can also use the buffering feature to reduce network usage. The typical use of the reverse proxy is to provide Internet users with access to the server behind the firewall. The reverse proxy can also provide load balancing for multiple back-end servers, or provide buffering services for servers with slower back-ends. In addition, the reverse proxy can also enable advanced URL policies and management technologies, so that web pages in different web server systems can exist in the same URL space at the same time.
In terms of security, the forward proxy allows clients to access any website through it and hides the client itself. Therefore, you must take security measures to ensure that services are only provided to authorized clients. The reverse proxy is transparent to the outside, and visitors do not know that they are accessing a proxy.

NGINX load balancing operation

lab environment

Three servers (7 or 6, reasonably allocated according to their own virtual machines)
2 Centos: 6
1 Centos: 7
role assignment
192.168.153.140 (Centos: 6) NGINX reverse proxy server
192.168.153.131 (Centos: 6) WEB server 1
192.168.153.179 (Centos: 7) WEB server 2

All three servers close the firewall and Selinux

Reverse proxy server (install NGINX)
WEB server (install httpd)

Start building

1. Operation on NGINX reverse proxy server:

1. The dependencies required to install nginx

[root@DB ~]# yum -y install gcc pcre-devel openssl-devel

2. Upload the nginx software package and install it (make a soft link)
&&and means, with &&, the commands can be executed sequentially

[root@DB ~]# ls
nginx-1.12.2.tar.gz
[root@DB ~]# tar xf nginx-1.12.2.tar.gz 
[root@DB ~]# cd nginx-1.12.2
[root@DB nginx-1.12.2]# ./configure && make && make install

Soft link

[root@DB nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx

3. Modify the nginx configuration file for load balancing

[root@DB nginx-1.12.2]# cd /usr/local/nginx/
[root@DB nginx]# vim conf/nginx.conf

Insert picture description here
Insert picture description here

4. Start nginx

[root@DB nginx]# nginx

2. Operations on WEB1:

1. Install apache

[root@DB2 ~]# yum -y install httpd

2. Modify the default test page to web1

[root@DB2 ~]# echo web1 > /var/www/html/index.html

3. Start apache

[root@DB2 ~]# service httpd start

4. Browser test

Insert picture description here

3. Operation on WEB2:
1. Install apache

[root@localhost ~]# yum -y install httpd

2. Modify the default test page to web2 (so you can see the effect of load balancing)

[root@localhost ~]# echo web2 > /var/www/html/index.html

3. Start apache

[root@localhost ~]# systemctl start httpd

4. The last step of browser testing
Insert picture description here
:

The browser enters the NGINX reverse proxy server IP to test the load balancing effect
Insert picture description here

Insert picture description here

At this point, our NGINX load balancing is completed, and there will be LVS, HAPROXY and other load balancing for everyone to learn

Guess you like

Origin blog.csdn.net/qq_49296785/article/details/107608860