Nginx reverse proxy, load balancing, and nginx reverse load

Source: Internet
Author: User
Tags nginx server nginx load balancing

Nginx reverse proxy, load balancing, and nginx reverse load
1What is reverse proxy and reverse proxy?

 

1.1 Forward proxy

 

1.2 Reverse Proxy

 

1.2 Use Nginx implements reverse proxy

Nginx only forwards requests. There are multiple http servers in the background to provide services. The nginx function is to forward requests to the backend servers and decide who to forward the requests.

 

1.2.1 Install tomcat

Create two tomcat instances on a virtual machine to simulate multiple servers.

 

1.2.2 Requirement

Access tomcat running on different ports by accessing different domain names

8080.itheima.com access tomcat running port 8080

8081.itheima.com access tomcat running port 8081

 

1.2.3 The host file must be configured for the domain name:

 

 

1.2.4 Nginx Configuration

Upstream tomcatserver1 {

Server 192.168.25.141: 8080;

}

Upstream tomcatserver2 {

Server 192.168.25.141: 8081;

}

Server {

Listen 80;

Server_name 8080.itheima.com;

 

# Charset koi8-r;

 

# Access_log logs/host. access. log main;

 

Location /{

Proxy_pass http: // tomcatserver1;

Index index.html index.htm;

}

 

}

Server {

Listen 80;

Server_name 8081.itheima.com;

 

# Charset koi8-r;

 

# Access_log logs/host. access. log main;

 

Location /{

Proxy_pass http: // tomcatserver2;

Index index.html index.htm;

}

 

}

 

If multiple servers provide services under the same domain name, nginx load balancing is required.

 

2 Server Load balancer2.1 What is Server Load balancer?

Server Load balancer is built on the existing network structure, it provides a cheap, effective, and transparent method to expand the bandwidth of network devices and servers, increase throughput, enhance network data processing capabilities, and improve network flexibility and availability.

Server Load balancer (Load Balance) is distributed to multiple operation units for execution, such as Web servers, FTP servers, enterprise key application servers, and other key task servers, to work together.

2.2 Requirement

Nginx acts as the Server Load balancer server. User requests first reach nginx, and then nginx forwards requests to the tomcat server according to the load configuration.

Nginx Server Load balancer: 192.168.25.141

Tomcat1 servers: 192.168.25.141: 8080

Tomcat2: 192.168.25.141: 8081

 

2.3 Configure nginx Server Load balancer

 

 

2.4 Configure the weight of the Server Load balancer instance

 

Node description:

Add:

 

# Define the Ip address and device status of the Server Load balancer Device

Upstream myServer {

 

Server 127.0.0.1: 9090 down;

Server 127.0.0.1: 8080 weight = 2;

Server 127.0.0.1: 6060;

Server 127.0.0.1: 7070 backup;

}

 

Add

 

Proxy_pass http: // myServer;

 

The status of each device in upstream:

 

Down indicates that the server before a ticket is not involved in the load

The default weight value is 1. The larger the weight value, the larger the load weight.

Max_fails: the default number of failed requests is 1. If the maximum number of failed requests is exceeded, an error defined by the proxy_next_upstream module is returned.

Fail_timeout: The pause time after max_fails failed.

Backup: Requests the backup machine when all other non-backup machines are down or busy. Therefore, this machine is under the least pressure.

 

3 High Availability of Nginx

The solution to high availability is to add redundancy.

 

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.