Nginx+Tomcat load balancing, dynamic and static separation

1. Nginx application

Nginx is a very good HTTP service software

  • Supports responses up to 50,000 concurrent connections
  • Possess powerful static resource processing capabilities
  • run smoothly
  • Very low consumption of system resources such as memory and CPU

At present, many large websites use the Nginx server as the reverse proxy and load balancer of the back-end website program to improve the load concurrency of the entire site.

1.1 Nginx load balancing implementation principle

insert image description here
The main parameters of Nginx configuration reverse proxy

  • upstream service pool name { }
    • Configure a pool of backend servers to serve response data
  • proxy_pass http://service pool name
    • Configure server processing that forwards access requests to the backend server pool

1.2 Nginx Dynamic and Static Separation Realization Principle

insert image description here
The principle of dynamic and static separation:
the server receives requests from the client, both static resources and dynamic resources, both static resources and dynamic resources, static resources are served by Nginx, and dynamic resources are forwarded to the backend by Nginx

Nginx static processing advantages:

  • The efficiency of Nginx in handling static pages is much higher than that of Tomcat
  • If Tomcat requests 1000 times, Nginx requests 6000 times
  • The throughput per second of Tomcat is 0.6M, and the throughput per second of Nginx is 3.6M
  • The ability of Nginx to handle static resources is 6 times that of Tomcat

2. Nginx+Tomcat load balancing, dynamic and static separation (seven-layer instance)

insert image description here

Nginx server: 192.168.174.75
Tomcat server 1: 192.168.174.76:8080
Tomcat server 2: 192.168.174.74:8080 192.168.174.74:8081

Configure Tomcat server 1:
insert image description here
insert image description here

vim index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP test3 page</title>
</head>
<body>
<% out.println("JSP动态页面 3");%>
</body>
</html>
~           

insert image description here

Configure Tomcat server 2:
insert image description here

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP test1 page</title>
</head>
<body>
<% out.println("JSP动态页面 1");%>
</body>
</html>

insert image description here

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP test2 page</title>
</head>
<body>
<% out.println("JSP动态页面 2");%>
</body>
</html>

insert image description here
insert image description here
Configure Nginx server:
insert image description here

vim nginx.repo

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

insert image description here
insert image description here
insert image description here

#定义后端服务器组的名称和节点配置
upstream backend_server {
    
    
         server 192.168.174.74:8080 weight=1;
         server 192.168.174.74:8081 weight=1;
         server 192.168.174.76:8080 weight=1;
}


#使用location匹配用户发来的.jsp动态页面请求给后端服务器组
    location ~* .*\.jsp$ {
    
    
             proxy_pass http://backend_server;
             #在转发报文里添加头部记录真实的客户端地址
             proxy_set_header HOST $host;
             proxy_set_header X-REAL-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     }

insert image description here

Test the static page effect:
insert image description here

Guess you like

Origin blog.csdn.net/Wanghwei17/article/details/131069762