159:静态资源服务器(如果之前做过PHP动静分离就不用改)

vi /etc/nginx/conf.d/default.conf
server {
    listen 80;
    server_name _;

    root /usr/share/nginx/html;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}
echo "STATIC-159" > /usr/share/nginx/html/index.html

160:Tomcat 动态服务器

dnf install -y java-17-openjdk
cd /opt
wget https://archive.apache.org/dist/tomcat/tomcat-10/v10.1.24/bin/apache-tomcat-10.1.24.tar.gz
tar -zxvf apache-tomcat-10.1.24.tar.gz
mv apache-tomcat-10.1.24 tomcat
/opt/tomcat/bin/startup.sh
echo '<h1>DYNAMIC-160 TOMCAT</h1>' > /opt/tomcat/webapps/ROOT/index.jsp
#重写配置文件
cat > /etc/nginx/conf.d/default.conf <<'EOF'
server {
    listen 80 default_server;
    server_name _;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}
EOF
setenforce 0
vim /opt/tomcat/webapps/ROOT/index.jsp
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <title>DYNAMIC-160 TOMCAT</title>
    <style>
        body {
            margin: 0;
            height: 100vh;
            background: radial-gradient(circle at center, #0f2027, #203a43, #2c5364);
            color: #00ffff;
            font-family: "Consolas", monospace;
            overflow: hidden;
        }

        .container {
            text-align: center;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }

        h1 {
            font-size: 60px;
            letter-spacing: 3px;
            text-shadow: 0 0 10px #00ffff, 0 0 40px #00ffff;
            animation: glow 2s infinite alternate;
        }

        @keyframes glow {
            from { text-shadow: 0 0 10px #00ffff; }
            to { text-shadow: 0 0 30px #00ffff, 0 0 60px #00ffff; }
        }

        .info {
            margin-top: 20px;
            font-size: 20px;
            color: #ffffff;
        }

        .box {
            margin-top: 30px;
            padding: 20px;
            border: 1px solid #00ffff;
            border-radius: 10px;
            box-shadow: 0 0 20px #00ffff;
        }

        .tag {
            color: #00ff88;
            font-weight: bold;
        }

        .pulse {
            margin-top: 30px;
            width: 20px;
            height: 20px;
            background: #00ffff;
            border-radius: 50%;
            margin-left: auto;
            margin-right: auto;
            animation: pulse 1s infinite;
        }

        @keyframes pulse {
            0% { box-shadow: 0 0 5px #00ffff; }
            50% { box-shadow: 0 0 20px #00ffff; }
            100% { box-shadow: 0 0 5px #00ffff; }
        }
    </style>
</head>
<body>

<div class="container">
    <h1>🚀 DYNAMIC-160</h1>

    <div class="box">
        <div class="info">
            Server: <span class="tag">Tomcat (160)</span><br>
            Type: <span class="tag">Dynamic Content</span><br>
            Time: <span class="tag"><%= new java.util.Date() %></span><br>
            Client IP: <span class="tag"><%= request.getRemoteAddr() %></span>
        </div>
    </div>

    <div class="pulse"></div>

    <div class="info" style="margin-top:20px;">
        ⚡ 动态请求由 160 处理(JSP 渲染)
    </div>
</div>

</body>
</html>

154:入口调度(Nginx)

vi /etc/nginx/conf.d/lb.conf
upstream static_backend {
    server 192.168.47.159;
}
upstream tomcat_backend {
    server 192.168.47.160:8080;
}
server {
    listen 80;
    server_name _;
    # 静态 → 159
    location ~* \.(html|css|js|png|jpg|gif)$ {
        proxy_pass http://static_backend;
        proxy_set_header Host $host;
    }
    # 动态 → Tomcat
    location / {
        proxy_pass http://tomcat_backend;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}
nginx -t
systemctl restart nginx

                   用户
                      ↓
        154(Nginx入口)
       ├───────────┐
       ↓                             ↓
   159静态            160 Tomcat
   HTML                  Java动态

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐