【nginx----------反向代理】

本文介绍了如何在Linux服务器上下载并安装ApacheTomcat8.5.63,配置两个不同的实例(8080和8081),以及如何使用Nginx作为反向代理,实现通过不同端口访问对应的篮球和足球Web应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、目标

浏览器网页中访问http://${Linux服务器的IP}:9001/basketball/index.html,浏览器中打印"篮球8080!!!";


浏览器网页中访问http://${Linux服务器的IP}:9001/football/index.html,浏览器中打印"足球8081!!!";

1、下载apache-tomcat-8.5.63.tar.gz安装包

cd /opt/tomcat
mkdir tomcat8080
mkdir tomcat8081

 cd tomcat8080---------------8080文件下操作

tar -zxvf apache-tomcat-8.5.63.tar.gz		
cd /opt/tomcat/tomcat8080/apache-tomcat-8.5.63/webapps/
mkdir basketball
vim index.html

创建文件index.html 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>首页</title>
</head>
<body>
  <p style="color: red;font-size: 30px" align="center">篮球8080!!!</p>
</body>
</html>

2、启动tomcat8080

cd /opt/tomcat/tomcat8080/apache-tomcat-8.5.63/bin
 
./startup.sh

测试:浏览器输入IP地址+8080

cd tomcat8081---------------8081文件下操作

tar -zxvf apache-tomcat-8.5.63.tar.gz		
cd /opt/tomcat/tomcat8080/apache-tomcat-8.5.63/webapps/
mkdir football
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>首页</title>
</head>
<body>
  <p style="color: red;font-size: 30px" align="center">足球8081!!!</p>
</body>
</html>

修改如下三个端口:--------------/tomcat8081/apache-tomcat-8.5.63/conf/server.xml文件

Server port、onnector port、redirectPort
onnector port 改为8081,其他改为与8080不相同的端口,防止冲突

启动tomcat8081

/opt/tomcat/tomcat8081/apache-tomcat-8.5.63/bin
./startup.sh

 测试:浏览器输入IP地址+8081

修改nginx配置文件----------------------nginx.conf


cd /usr/local/nginx/conf/
 
vim nginx.conf
server {
        listen       9009;
        server_name  localhost;
 
        location ~ /basketball/ {
            proxy_pass http://127.0.0.1:8080;
        }
 
        location ~ /football/ {
            proxy_pass http://127.0.0.1:8081;
        }
}

重新加载nginx配置

./nginx -s reload

【测试】
http://192.168.88.152:9009/basketball/index.html
 
http://192.168.88.152:9009/football/index.html 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值