? ? ? ? ? ?具体步骤请看我之前的博客
写文章-CSDN创作中心https://mp.csdn.net/mp_blog/creation/editor/134956765?spm=1001.2014.3001.9457
mkdir /usr/local/tomcat/webapps/test
vim /usr/local/tomcat/webapps/test/index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP test1 page</title> #指定为 test1 页面
</head>
<body>
<% out.println("动态页面 1,http://www.test1.com");%>
</body>
</html>
?
测试一下:
##先定义一个后端服务器池的名称为tomcat server 这名称自定义的,会与后面调用相关联对用三个tomcat服务
upstream tomcat_server {
server 192.168.136.100:8080 weight=1;
server 192.168.136.110:8080 weight=1;
server 192.168.136.110:8081 weight=1;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#location匹配到以jsp结尾的请求 转发给后端服务器池proxy_pass http:// 表示基于http协议进行转发,这是七层反向代理
location ~ .*\.jsp$ {
proxy_pass http://tomcat_server;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#access_log logs/host.access.log main;
#location匹配静态请求那么由nginx自身处理
location / {
root html;
index index.html index.htm;
}
location ~ .*\.jsp$ {
proxy_pass http://tomcat_server;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#access_log logs/host.access.log main;
location /static {
root html;
index index.html index.htm;
}
130主机:
140主机:
192.168.136.130的动静分离验证
静态:
动态:
?
动态页面请求验证
192.168.136.140的动静分离验证
静态:
动态:
?
stream {
14
15 upstream nginx_server {
16 server 192.168.136.130:80;
17 server 192.168.136.140:80;
18 }
19 server {
20 listen 9527;
21 proxy_pass nginx_server;
22 }
23 }
?
?