Nginx+Tomcat负载均衡、动静分离

七层反向代理+动静分离

Nginx+Tomcat负载均衡、动静分离_第1张图片

实验配置:
nginx:20.0.0.61 代理又是静态
tomcat1:20.0.0.71
tomcat2:20.0.0.72
[root@nginx1 conf]# vim nginx.conf

http {
    ...
    upstream tomcat {
        server 20.0.0.71:8080 weight=1;
        server 20.0.0.72:8080 weight=1;
    }
    server {
        ...
        location / {
            root   html;
            index  index.html index.htm;
        }

        location ~* \.jsp$ {
            proxy_pass http://tomcat;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

[root@nginx1 conf]# nginx -t
[root@nginx1 conf]# systemctl restart nginx

Nginx+Tomcat负载均衡、动静分离_第2张图片

Nginx+Tomcat负载均衡、动静分离_第3张图片

[root@nginx1 conf]# cd ..
[root@nginx1 nginx]# cd html/
[root@nginx1 html]# vim index.html



this is Nginx static test1 !

--传入naruto.PNG--

浏览器访问20.0.0.61

Nginx+Tomcat负载均衡、动静分离_第4张图片

[root@tomcat1 ~]# cd /usr/local/tomcat/
[root@tomcat1 tomcat]# cd webapps/
[root@tomcat1 webapps]# mkdir test
[root@tomcat1 webapps]# cd test/
[root@tomcat1 test]# vim index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


JSP test1 page


<% out.println("动态页面 1,http://www.test1.com");%>



[root@tomcat2 ~]# cd /usr/local/tomcat/
[root@tomcat2 tomcat]# cd webapps/
[root@tomcat2 webapps]# mkdir test
[root@tomcat2 webapps]# cd test/
[root@tomcat2 test]# vim index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


JSP test2 page


<% out.println("动态页面 2,http://www.test2.com");%>


71、72相同操作:
[root@tomcat1 conf]# vim server.xml
--删除--

--插入--
        

71、72相同操作:
[root@tomcat1 conf]# cd ..
[root@tomcat1 tomcat]# cd bin/
[root@tomcat1 bin]# ./startup.sh 

浏览器直接访问71、72动态页面

Nginx+Tomcat负载均衡、动静分离_第5张图片

Nginx+Tomcat负载均衡、动静分离_第6张图片

浏览器访问代理服务器跳转至动态页面

Nginx+Tomcat负载均衡、动静分离_第7张图片

Nginx+Tomcat负载均衡、动静分离_第8张图片

四层+七层+动静分离

Nginx+Tomcat负载均衡、动静分离_第9张图片

实验配置:
nginx代理:20.0.0.61
静态页面和动态请求转发服务器:
nginx2:20.0.0.62
nginx3:20.0.0.63
tomcat1:20.0.0.71
tomcat2:20.0.0.72
[root@nginx1 conf]# vim nginx.conf

stream {
        upstream static {
            server 20.0.0.62:80 weight=1;
            server 20.0.0.63:80 weight=1;
        }
    server {
        listen 80;
        proxy_pass static;
    }
}

[root@nginx1 conf]# nginx -t
[root@nginx1 conf]# systemctl restart nginx

Nginx+Tomcat负载均衡、动静分离_第10张图片

62、63相同操作:
[root@nginx2 conf]# vim nginx.conf

upstream tomcat {
        server 20.0.0.71:8080 weight=1;
        server 20.0.0.72:8080 weight=1;
}

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }
         location ~* \.jsp$ {
            proxy_pass http://tomcat;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

Nginx+Tomcat负载均衡、动静分离_第11张图片

[root@nginx2 html]# vim index.html 



this is Nginx static test !

--传入naruto.PNG-- [root@nginx3 html]# vim index.html

this is Nginx static test !

--传入sasuke.PNG--

浏览器访问20.0.0.61请求静态页面

Nginx+Tomcat负载均衡、动静分离_第12张图片

Nginx+Tomcat负载均衡、动静分离_第13张图片

浏览器访问20.0.0.61动态页面跳转

Nginx+Tomcat负载均衡、动静分离_第14张图片

Nginx+Tomcat负载均衡、动静分离_第15张图片

你可能感兴趣的:(firefox,safari,前端)