Test purpose: To access the Nginx IP address on an nginx server, the test page of three different Tomcat servers on the back end will be displayed once refreshed.
Test environment: three CentOS 6.8
One CentOS 7.3
Software version: Nginx 1.12.1
Tomcat 8
Software deployment will not operate the previous deployment has been done, not to see my previous blog has.
Nginx Installation
http://dklwj.blog.51cto.com/9199080/1949570
Tomcat Installation:
http://dklwj.blog.51cto.com/9199080/1955403
Make some changes on three tomcat.
1, the/usr/local/tomcat/webapps under the original things are deleted except the root directory to keep, but the root directory of things can be emptied and then we use the test page and the required documents to put in.
[[email protected] root]# ls
Classes index.jsp Lib Meta-inf web-inf-the words of these files are the files that Java must have
Then edit the index.jsp file, the next two words from the first configuration of the server copy of the previous changes under the title here I will use a, B, C to replace the three Server page test title. Then save and exit.
[Email protected] root]# vim index.jsp
<%@ page language= "java"%>
<title>tomcatB</title>
<body>
<table align= "centre" border= "1" >
<tr>
<td>session id</td>
<% Session.setattribute ("dklwj.com", "dklwj.com"); %>
<td> <%= Session.getid ()%></td>
</tr>
<tr>
<td>created on </td>
<td><%= session.getcreationtime ()%></td>
</tr>
</table>
</body>
Start Tomcat
[Email protected] ~]$/usr/local/tomcat/bin/startup.sh
Using catalina_base:/usr/local/tomcat
Using Catalina_home:/usr/local/tomcat
Using Catalina_tmpdir:/usr/local/tomcat/temp
Using Jre_home:/USR/LOCAL/JDK
Using CLASSPATH:/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
Use SS-TNL to see if the lower port is being monitored.
[Email protected] ~]# SS-TNL
State recv-q send-q Local address:port Peer address:port
LISTEN 0 1:: ffff:127.0.0.1:8005:::*
LISTEN 0::: 8009:::*
LISTEN 0::: 8080:::*
LISTEN 0::: $:::*
LISTEN 0 *:22 *:*
The other two tomcat configurations are ignored here.
Configuring the Nginx Server
[Email protected] ~]# cd/etc/nginx/
[Email protected] nginx]# vim nginx.conf
Under the HTTP configuration bar, add the following paragraph
Upstream Tcsrvs {
Server 192.168.2.32:8080;
Server 192.168.2.38:8080;
Server 192.168.2.39:8080;
}
Add in the server configuration and keep exiting;
server {
Listen 80;
server_name localhost;
#charset Koi8-r;
#access_log Logs/host.access.log Main;
Location/{
root HTML;
Index index.html index.htm;
Proxy_pass Http://tcsrvs;
}
Use NGINX-T to check the configuration file for errors.
[Email protected] nginx]# nginx-t
Nginx:the configuration file/etc/nginx/nginx.conf syntax is OK
Nginx:configuration file/etc/nginx/nginx.conf Test is successful
[Email protected] nginx]#
Then the browser verification: a refresh to jump to the other two up, indicating that the test was successful.
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/A3/3B/wKioL1mj7c_Tb7AeAABDYdw0gtE085.jpg-wh_500x0-wm_ 3-wmp_4-s_1794468385.jpg "style=" Float:none; "title=" tomcat1.jpg "alt=" wkiol1mj7c_tb7aeaabdydw0gte085.jpg-wh_50 "/ >
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/04/8B/wKiom1mj7eGBPLdjAABDBEdZ9_4161.jpg-wh_500x0-wm_ 3-wmp_4-s_2648981917.jpg "style=" Float:none; "title=" tomcat2.jpg "alt=" wkiom1mj7egbpldjaabdbedz9_4161.jpg-wh_50 "/ >
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/04/8B/wKiom1mj7eHCaElWAAA7Pr2rhxI682.jpg-wh_500x0-wm_ 3-wmp_4-s_422553470.jpg "style=" Float:none; "title=" tomcat3.jpg "alt=" wkiom1mj7ehcaelwaaa7pr2rhxi682.jpg-wh_50 "/ >
Some places have problems, but also ask the big guys to point out! Thank you very much!!
Linux Tomcat Load balancer based on Nginx