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
總結
以上是生活随笔為你收集整理的tomcat 反代配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: P3834 【模板】可持久化线段树 1(
- 下一篇: 贷款余额是指什么意思 需要归还的钱