环境:
1 nginx-proxy-server: 2 IP:192.168.1.131 3 [root@gz01-nginx-proxy-master ~]# uname -r 4 3.10.0-693.el7.x86_64 5 [root@gz01-nginx-proxy-master ~]# cat /etc/redhat-release 6 CentOS Linux release 7.4.1708 (Core) 7 8 tomcat集群:(查看前面单机多实例部署) 9 IP:192.168.1.124:8080 10 IP:192.168.1.124:8081 11 IP:192.168.1.124:8082 12 IP:192.168.1.124:8083 13 [root@gz01-tomcat-node01 ~]# uname -r 14 3.10.0-693.el7.x86_64 15 [root@gz01-tomcat-node01 ~]# cat /etc/redhat-release 16 CentOS Linux release 7.4.1708 (Core)
直接在nginx-proxy-server上设置跳转
1 [root@gz01-nginx-proxy-master ~]# vim /usr/local/nginx/conf/nginx.conf
2 location / {
3 proxy_pass http://192.168.1.131:8080;
4
5 }
6 location ~* \.(jsp|do)$ {
7 proxy_pass http://192.168.1.131;
8 proxy_set_header Host $host;
9 }[root@gz01-nginx-proxy-master ~]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx-1.8.1/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx-1.8.1/conf/nginx.conf test is successful[root@gz01-nginx-proxy-master ~]# /usr/local/nginx/sbin/nginx -s reload
访问测试,http://192.168.1.131/

设置集群代理服务:
1 [root@gz01-nginx-proxy-master ~]# vim /usr/local/nginx/conf/nginx.conf
2
3 http {
4
5 include mime.types;
6 default_type application/octet-stream;
7 upstream tomcatlist {
8 server 192.168.1.124:8080 weight=1;
9 server 192.168.1.124:8081 weight=2;
10 server 192.168.1.124:8082 weight=3;
11 server 192.168.1.124:8083 weight=4;
12 }
13
14 location / {
15
16 proxy_pass http://tomcatlist;
17
18 }
19
20 location ~* \.(jsp|do)$ {
21
22 proxy_pass http://tomcatlist;
23 proxy_set_header Host $host;
24 }
[root@gz01-nginx-proxy-master ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.8.1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.8.1/conf/nginx.conf test is successful
[root@gz01-nginx-proxy-master ~]# /usr/local/nginx/sbin/nginx -s reload
创建测试页面
1 192.168.1.124:8080
2 <%@ page language="java" %>
3 <%@ page import="java.util.*" %>
4 <html>
5 <head>
6 <title>Test Page</title>
7 </head>
8 <body>
9 <% out.println("Tomcat 192.168.1.124:8080");%>
10 </body>
11 </html>
12 192.168.1.124:8081
13 <%@ page language="java" %>
14 <%@ page import="java.util.*" %>
15 <html>
16 <head>
17 <title>Test Page</title>
18 </head>
19 <body>
20 <% out.println("Tomcat 192.168.1.124:8081");%>
21 </body>
22 </html>
23 192.168.1.124:8082
24 <%@ page language="java" %>
25 <%@ page import="java.util.*" %>
26 <html>
27 <head>
28 <title>Test Page</title>
29 </head>
30 <body>
31 <% out.println("Tomcat 192.168.1.124:8082");%>
32 </body>
33 </html>
34 192.168.1.124:8083
35 <%@ page language="java" %>
36 <%@ page import="java.util.*" %>
37 <html>
38 <head>
39 <title>Test Page</title>
40 </head>
41 <body>
42 <% out.println("Tomcat 192.168.1.124:8083");%>
43 </body>
44 </html>
页面访问测试




来源:https://www.cnblogs.com/xiaozhebao/p/12596224.html