Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the server's load balancing nginx+tomcat to achieve static and dynamic separation

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to use the server's Load Balancer nginx+tomcat to realize static separation." The editor shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "how to use the server's Load Balancer nginx+tomcat to realize static separation" can help you solve the problem.

Case environment

host information

architecture diagram

Case study: tomcat server deployment

Prepare jdk and tomcat on two tomcat servers

jdk download

tomcat download

mkdir /toolscd /toolslsapache-tomcat-8.5.70.tar.gz jdk-8u181-linux-x64.tar.gz

install the JDK

mkdir -p /app/javatar xf jdk-8u181-linux-x64.tar.gz -C /app/ln -s /app/jdk1.8.0_181/ /app/jdkvim /etc/profileexport JAVA_HOME=/app/jdkexport CLASSPATH=.:$ JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jarexport PATH=$PATH:$JAVA_HOME/binsource /etc/profilejava -versionjava version "1.8.0_181"Java(TM) SE Runtime Environment (build 1.8.0_181-b13)Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

Deploying tomcat

tar xf apache-tomcat-8.5.70.tar.gz -C /appln -s /app/apache-tomcat-8.5.70/ /app/tomcat

Start tomcat and test, tomcat default start port 8080

/app/tomcat/bin/startup.shss -anpt | grep 8080LISTEN 0 100 [::]:8080 [::]:* users:(("java",pid=2375,fd=52))

See the above page to indicate successful deployment

Create tomcat01 Site Home

rm -rf /app/tomcat/webapps/ROOT/*cat /app/tomcat/webapps/ROOT/index.jsp tomcat01

Create womcat02 Site Home

rm -rf /app/tomcat/webapps/ROOT/*cat /app/tomcat/webapps/ROOT/index.jsp tomcat02

Two tomcat servers restart service

The requested URL/app/tomcat/bin/shutdown.sh was not found on this server.

Install nginx dependencies

yum -y install gcc gcc-c++ autoconf pcre-devel make automake httpd-tools enopssl-devel

Configure nginx software sources

cat /etc/yum.repos.d/nginx.repo [nginx-stable]name=nginx stable repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=1enabled=1gpgkey=https://nginx.org/keys/nginx_signing.keymodule_hotfixes=true

Install nginx service and start

yum clean allyum makecacheyum -y install nginxsystemctl enable --now nginx

yum installed nginx has profile separation enabled, we use the default profile

cat /etc/nginx/nginx.confinclude /etc/nginx/conf.d/*.conf;#Modify default configuration file vim /etc/nginx/conf.d/default.confserver { listen 80; server_name 192.168.10.3;

Create a new website

The requested URL/html/index.html was not found on this server. body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; }

Restart nginx service

systemctl reload nginx

Ah, pictures.

Deploying nginx-lb servers

The installation steps are the same as the first three steps of nginx01

Create a Load Balancer Profile

vim /etc/nginx/conf.d/proxy.confupstream tomcat { server 192.168.10.4:8080; server 192.168.10.5:8080;}upstream static { server 192.168.10.3:80;}server { listen 80; server_name 192.168.10.2; location / { proxy_pass http://tomcat; } location ~* .*\. (png|gif|jpg)$ { proxy_pass http://static; }}

Restart nginx service

nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successfulsystemctl reload nginx

The principle is that tomcat backend server will be accessed by default, but static backend will be accessed when there are static images in the web page.

Access Test: Achieve a Load Balancer and Static and Dynamic Separation

About "how to use the server Load Balancer nginx+tomcat to achieve static separation" content introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report