tomcat 反代配置
tomcat反代可以基于nginx , http進(jìn)行反代
反代服務(wù)器: 有兩個網(wǎng)口? 反代服務(wù)器一般有兩塊網(wǎng)卡一塊處于外網(wǎng),一塊處于內(nèi)網(wǎng)用于與后端服務(wù)器通信
tomcat 節(jié)點(diǎn)處于內(nèi)網(wǎng)地址
1 tomcat安裝
1 安裝jdk等軟件包
yum? install? java-1.8.0-openjdk-devel?? tomcat? tomcat-webapps? tomcat-admin-webapps? tomcat-docs-webapp??? -y
?2 啟動服務(wù):systemctl?? start? tomcat.service
tomcat安裝完成
nginx反代服務(wù)器:
1 安裝nginx
yum? install? nginx?? -y
2 配置配置文件 ,在conf.d下配置個虛擬機(jī),通過虛擬機(jī)進(jìn)行反代
vim?? ilinux.conf
server? {
????? listen? 80;
????? server? name? www.ilinux.io;
????? location? /? {
?????????? proxy_pass?? http://192.168.10.11:8080;
????? }
}
nginx? -t? ? 檢查語法
啟動nginx服務(wù):
?systemctl?? start? nginx.service??
訪問:www.ilinux.io???? 訪問之前在/etc/hosts 下做域名解析
如這里給tomcat一個test測試頁
mkdir?? -pv? /var/lib/tomcat/webapps/test/{WEB-INF,META-INF,classes,lib}
創(chuàng)建主頁面
: 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也可以實現(xiàn)動靜分離
location??? /?? {
?????????? proxy_pass? http://192.168.1.15:80;
????? }
????? location? ~* \.{jsp|do}$?? {
?????????? proxy_pass http://192.168.10.11:8080;
????? }
?
使用http實現(xiàn)反代
? ? ? yum install?? httpd??? -y
http做反代有兩種模式
一種是httpd協(xié)議? 一種jsp協(xié)議
# httpd?? -M?? 查看模塊的
其中:
proxy _module? {shared}??? 是主模塊起反代功能的必須啟用
proxy_http_module {shared}?? 基于httpd協(xié)議進(jìn)行反代的
proxy_ajp_module (shared)?? 基于ajp協(xié)議進(jìn)行反代的
配置文件設(shè)置
vim?? conf.d/ilinux-tomcat.conf
<VirutalHost? *:80>
????? ServerName??? www.ilinux.io
????? DocumentRoot? “/data/ilinux/htdocs”
????? ProxyRequests Off??????????????????????? 禁止正向代理
????? ProxyPreserveHost On???????????????? 是否把響應(yīng)報文的host首部一并轉(zhuǎn)到后端
????? ProxyVia??? on
????? <Proxy *>??? ????????????? 定那些用戶訪問權(quán)限的
????? Require all granted
????? </Proxy>
????? ProxyPass / http://tc1.magedu.com:8080/??????????????? 把根 反代到那
????? ProxyPassReverse / http://tc1.magedu.com:8080/ ????????? 若后端有重定向
????? <Location />?????? ?????????? 定義基于根的訪問權(quán)限
????? Require all granted
????? </Location>
</VirutalHost>
httpd? -t? 測試語法
啟動服務(wù)
訪問: 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>
?
轉(zhuǎn)載于:https://www.cnblogs.com/huxl1/p/9538127.html
總結(jié)
以上是生活随笔為你收集整理的tomcat 反代配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: P3834 【模板】可持久化线段树 1(
- 下一篇: 贷款余额是指什么意思 需要归还的钱