tomcat 反代配置

tomcat反代可以基于nginx , http进行反代

反代服务器: 有两个网口  反代服务器一般有两块网卡一块处于外网,一块处于内网用于与后端服务器通信

tomcat 节点处于内网地址

1 tomcat安装

  1 安装jdk等软件包

yum  install  java-1.8.0-openjdk-devel   tomcat  tomcat-webapps  tomcat-admin-webapps  tomcat-docs-webapp    -y

 2 启动服务:systemctl   start  tomcat.service

tomcat安装完成

nginx反代服务器:

1 安装nginx

yum  install  nginx   -y

2 配置配置文件 ,在conf.d下配置个虚拟机,通过虚拟机进行反代

vim   ilinux.conf

server  {

      listen  80;

      server  name  www.ilinux.io;

      location  /  {

           proxy_pass   http://192.168.10.11:8080;

      }

}

nginx  -t    检查语法

启动nginx服务:

 systemctl   start  nginx.service  

访问:www.ilinux.io     访问之前在/etc/hosts 下做域名解析

如这里给tomcat一个test测试页

mkdir   -pv  /var/lib/tomcat/webapps/test/{WEB-INF,META-INF,classes,lib}

创建主页面

: vim /var/lib/tomcat/webapps/test/index.jsp

<%@ page language="java" %>

<html>

      <head><title>TomcatA</title></head>

      <body>

           <h1><font color="red">TomcatA.magedu.com</font></h1>

           <table align="centre" border="1">

                 <tr>

                      <td>Session ID</td>

                 <% session.setAttribute("magedu.com","magedu.com"); %>

                    <td><%= session.getId() %></td>

                 </tr>

                 <tr>

                      <td>Created on</td>

                          <td><%= session.getCreationTime() %></td>

                 </tr>

           </table>

      </body>

</html>

访问:www.ilinux.io/test

若有两个tomcat也可以实现动静分离

location    /   {

           proxy_pass  http://192.168.1.15:80;

      }

      location  ~* \.{jsp|do}$   {

           proxy_pass http://192.168.10.11:8080;

      }

 

使用http实现反代

      yum install   httpd    -y

http做反代有两种模式

一种是httpd协议  一种jsp协议

# httpd   -M   查看模块的

其中:

proxy _module  {shared}    是主模块起反代功能的必须启用

proxy_http_module {shared}   基于httpd协议进行反代的

proxy_ajp_module (shared)   基于ajp协议进行反代的

配置文件设置

vim   conf.d/ilinux-tomcat.conf

<VirutalHost  *:80>

      ServerName    www.ilinux.io

      DocumentRoot  “/data/ilinux/htdocs”

      ProxyRequests Off                        禁止正向代理

      ProxyPreserveHost On                 是否把响应报文的host首部一并转到后端

      ProxyVia    on

      <Proxy *>                  定那些用户访问权限的

      Require all granted

      </Proxy>

      ProxyPass / http://tc1.magedu.com:8080/                把根 反代到那

      ProxyPassReverse / http://tc1.magedu.com:8080/           若后端有重定向

      <Location />                  定义基于根的访问权限

      Require all granted

      </Location>

</VirutalHost>

httpd  -t  测试语法

启动服务

访问: wwwilinux.io/

2 基于proxy_ajp_module模块代理配置示例:

<VirtualHost *:80>

      ServerName      tc1.magedu.com

   ProxyRequests Off

   ProxyVia        On

   roxyPreserveHost On

   <Proxy *>

              Require all granted

   </Proxy>

   ProxyPass / ajp://tc1.magedu.com:8009/

   ProxyPassReverse / ajp://tc1.magedu.com:8009/

   <Location />

      Require all granted

   </Location>

</VirtualHost>

 

转载于:https://www.cnblogs.com/huxl1/p/9538127.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值