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

Installation, configuration and integration of Nginx and tomcat

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article will explain in detail the installation, configuration and integration of Nginx and tomcat. The content of the article is of high quality, so I hope you can get something after reading this article.

Advantages and functions of nginx

Nginx is a high-performance HTTP and reverse proxy server, as well as an IMAP / POP3 / SMTP proxy server. It mainly has the following advantages:

High concurrent connections: the official test can support 50,000 concurrent connections, reaching 20,000 to 30,000 concurrent connections in the actual production environment.

Low memory consumption: under 30,000 concurrent connections, 10 Nginx processes open consume less than 150m (15m * 10 = 150m).

The configuration file is very simple: the style is as easy to understand as the program.

Low cost: Nginx is open source software and can be used for free. On the other hand, it costs more than 100,000 to hundreds of thousands of RMB to buy hardware load balancing switches such as F5 BIG-IP,NetScaler.

Support rewriting rules: HTTP requests can be divided into different host server groups according to domain name and URL.

Built-in health check function: if one of Nginx Proxy's previous Web servers goes down, the front-end access will not be affected.

Bandwidth savings: GZIP compression is supported, and Header headers can be added to the browser's local cache.

High stability: for reverse proxy, the probability of downtime is very small.

Because of the good performance of nginx, many large domestic companies are using it, and the main reason is that nginx is open source and free. In addition to the various functions described above, the project mainly uses nginx to implement the following three functions:

Dynamic and static separation

Reverse proxy

Load balancing http://www.daiqiyang.com

Web pages, picture caching

13.1.2 there are five main strategies for nginx load balancing

Minimum (minimum) each request is assigned to a different server one by one in chronological order, and if the server is lowered, it can be automatically eliminated.

Weight specifies the predetermined probability, and the weight is proportional to the access ratio, which is used in the case of uneven performance of the scheduled server.

Ip_hash each request is allocated according to the hash result of accessing the ip, so that each guest has a fixed access to a host server, which can solve the problem of the session.

Fair (third party) allocates requests through the response time of the server, giving priority to those with short response time.

Url_hash (third party) distributes requests by accessing the hash results of url, so that each URL is directed to the same placement server, thus making it more efficient when the server is cached.

Install Nginx

Yum-y install gcc gcc-c + + pcre-devel openssl-devel openssl wget

Wget http://nginx.org/download/nginx-1.12.2.tar.gz

Tar-zxvf nginx-1.12.2.tar.gz

Cd nginx-1.12.2

. / configure-- prefix = / usr / local / nginx

Make

Carry out installation

Install Tomcat

Install the jdk environment and test

[root@ c6s02] # tail-5 / etc/profile

# java_env####

Export JAVA_HOME=/usr/local/jdk1.8.0_60

Export PATH=JAVAHOME/bin:

JAVAHOME/bin:JAVA_HOME/jre/bin:$PATH

Export CLASSPATH=.CLASSPATH:

CLASSPATH:JAVA_HOME/lib:JAVAHOME/jre/lib:

JAVAHOME/jre/lib:JAVA_HOME/lib/tools.jar

Source / etc/profile

[root@ c6s02 ~] # java-version

Java version "1.8.0mm 60"

Java ™SE Runtime Environment (build 1.8.0_60-b27)

Java HotSpot ™64-Bit Server VM (build 25.60-b23, mixed mode)

Install tomcat (two subsystems)

Tar-zxvf apache-tomcat-7.0.47.tar.gz

# create a new tomcat01 project

Mkdir-p / opt/tomcat01

Cp-an apache-tomcat-7.0.47/* / opt/tomcat01/

# create a new tomcat02 project, and modify the three ports to 18005, 18080, 18009

Mkdir-p / opt/tomcat021

Cp-an apache-tomcat-7.0.47/* / opt/tomcat02/

# manually create a test page and test

Echo 'this is tomcat01' > / opt/tomcat01/webapps/ROOT/index.jsp

Echo 'this is tomcat02' > / opt/tomcat02/webapps/ROOT/index.jsp

Curl 10.0.0.22:8080/index.jsp

Curl 10.0.0.22:18080/index.jsp

Through Nginx and Tomcat combination

Install nginx and modify the Nignx configuration file

Vim / usr/local/nginx/conf/nginx.conf

Add to the HTTP module:

Upstream tomcat {# define server group tomcat

Server 10.0.0.22 8080; # defined Tomcat server

Server 10.0.0.22:18080

}

Add to the server module:

Location ~ .jsp ${# URL regular match, matching all URL at the end of jsp

Proxy_pass http://tomcat; # proxy_pass reverse proxy parameter to reverse proxy the matching request to the tomcat server group!

}

After reading this article, have you learned the installation, configuration and integration of Nginx and tomcat? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel. Thank you for reading.

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

Servers

Wechat

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

12
Report