以LNMP为例,一个企业内部最基础的架构组成需要一个处理静态Web服务的页面,一个动态Web服务的页面和数据库
而我们实现了在Linux平台上,实现了Nginx + PHP 实现动静分离,而实际生产中往往一台nginx 需要“对应”多个动态处理的服务(及tomcat),所以如何将前端接收到的动态请求转交给后端多个tomcat处理
nginx 192.168.200.12
tomcat1 192.168.200.11
tomcat2 192.168.200.13
(nginx和tomcat安装参考之前的博客)
- 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>
- </head>
- <body>
- <% out.println("动态页面 1,http://www.test1.com");%>
- </body>
- </html>
- vim /usr/local/tomcat/conf/server.xml
- 删除原host端和valve端
- <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
- <Context docBase="/usr/local/tomcat/webapps/test" path="" reloadable="true" /> #新增
- ---》wq
- shutdown.sh
- startup.sh
- 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 test2 page</title>
- </head>
- <body>
- <% out.println("动态页面 2,http://www.test2.com");%>
- </body>
- </html>
- vim /usr/local/tomcat/conf/server.xml #修改配置文件
-
- <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
- <Context docBase="/usr/local/tomcat/webapps/test" path="" reloadable="true" />
- </Host> #新增
- shutdown.sh
- startup.sh
- #准备静态页面
- echo '
this is static
' > /usr/local/nginx/html/index.html - vim /usr/local/nginx/conf/nginx.conf
- #gzip on;
- upstream tomcat_server {
- server 192.168.200.11:8080 weight=1;
- server 192.168.200.13:8080 weight=1;
- }
-
- server {
- listen 80;
- server_name www.lxx.com;
-
- #charset koi8-r;
-
- #access_log logs/host.access.log main;
- 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;
- }
-
- location / {
- root html;
- index index.html index.htm;
- }
-
- #error_page 404 /404.html;
-
- # redirect server error pages to the static page /50x.html
- #
测试一哈,同一个ip,一直刷新会两个界面轮换