• tomcat---动静分离


    访问静态和动态页面分开

    实现动态的静态页面负载均衡

    实验一

    准备阶段:三台虚拟机

    nginx代理服务器 :20.0.0.40

    tomcat1 :20.0.0.50

    tomcat2:20.0.0.51

    配置关闭虚拟机防火墙和安全机制

    systemctl stop firewalld

    setenforce 0
    配置nginx代理服务器 conf/nginx

    1. upstream tomcat {
    2. server ip1:8080 weight=2;
    3. server ip2:8080 weight=3;
    4. }
    5. location ~* \.jsp$ {
    6. proxy_pass http://tomcat;
    7. proxy_set_header HOST $host;
    8. proxy_set_header X-Real-IP $remote_addr;
    9. proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for;
    10. #在nginx作为代理服务器时,会把所有经过的机器的IP,以及代理地址的IP全部记录下来
    11. }

    nginx -t 检测配置文件是否有错

    systemctl restart nginx 重启服务

    切换到html目录下 cd /html

    1. <html>
    2. <body>
    3. <h1>this is Nginx static test !!<h1>
    4. <img src="图片">
    5. </body>
    6. </html>

    配置后端tomcat

    进入webapps目录下创建一个目录,在目录下创建index.jsp

    1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    2. <html>
    3. <head>
    4. <title>tomcat01</title>
    5. </head>
    6. <body>
    7. <% out.println("tomcat01 running");%>
    8. </body>
    9. </html>

    进入主配置文件并做备份 conf/server.conf

    1. #删除前面的 HOST 配置
    2. <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
    3. <Context docBase="/usr/local/tomcat/webapps/test" path="" reloadable="true" />
    4. </Host>

    然后进入bin目录下启动tomcat

    1. ./shutdown.sh
    2. ./stratup.sh

    查看8080端口是否启动

    netstat -antp | grep 8080

    同理tomcat也是上述操作

    实验二

    四层+7层+动静分离

    五台服务器

    1、代理服务器nginx1:20.0.0.40

    2、静态页面和动态的请求转发服务器

    20.0.0.41

    20.0.0.42

    3、后端服务器

    tomcat1:20.0.0.50

    tomcat2:20.0.0.51

    配置代理服务器

    1. stream {
    2. upstream static {
    3. server 20.0.0.50:80 weight=1;
    4. server 20.0.0.60:80 weight=1;
    5. }
    6. server {
    7. listen 80;
    8. proxy_pass static;
    9. }
    10. }

    转发服务器

    1. upstream tomcat {
    2.    server tomcatip1:8080 weight=1;
    3.    server tomcatip2:8080 weight=2;
    4. }
    5. location ~* \.jsp$ {
    6.    proxy_pass http://tomcat;
    7.    proxy_set_header HOST $host;
    8.    proxy_set_header X-Real-IP $remote_addr;
    9.    proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for;
    10.    #在nginx作为代理服务器时,会把所有经过的机器的IP,以及代理地址的IP全部记录下来
    11.  }

    配置静态页面的命令

    1. <html>
    2. <body>
    3. <h1>this is Nginx static test !!<h1>
    4. <img src="图片">
    5. </body>
    6. </html>

    同理nginx2也是一样的

    tomcat不需要动,实验一已经配置完毕

    在浏览器上20.0.0.40可以查看静态

    20.0.0.40/index.jsp查看动态

  • 相关阅读:
    【云原生】初识 Service Mesh
    java的包装类
    Axure设计之引入ECharts图表
    Remote Sensing投稿修改意见整理
    力扣之斐波那契数列
    基于Netty的TCP服务框架
    解决库存扣减及订单创建时防止并发死锁的问题
    CRYPTOHACK BLOCK CIPHERS
    阿里云服务器安全组开放指定端口无法访问问题记录
    java-net-php-python-jsp网络考试系统计算机毕业设计程序
  • 原文地址:https://blog.csdn.net/qq_71147683/article/details/133903018