系列六、Nginx配置实例之反向代理2

本文详细描述了如何在Linux服务器上部署两个不同端口的Tomcat实例(8080和8081),并使用Nginx进行反向代理,以便通过统一的9001端口访问篮球和足球Web应用。

一、目标

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

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

二、步骤

2.1、在/opt/tomcat目录分别创建tomcat8080、tomcat8081文件夹

cd /opt/tomcat

mkdir tomcat8080

mkdir tomcat8081

2.2、上传apache-tomcat-8.5.63.tar.gz安装包至tomcat8080、tomcat8081文件件

2.3、tomcat8080配置

2.3.1、解压

tar -zxvf apache-tomcat-8.5.63.tar.gz

2.3.2、在/opt/tomcat/tomcat8080/apache-tomcat-8.5.63/webapps/目录创建basketball文件夹

cd /opt/tomcat/tomcat8080/apache-tomcat-8.5.63/webapps/

mkdir basketball

2.3.3、上传index.html至basketball文件夹,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.3.4、启动tomcat8080

/opt/tomcat/tomcat8080/apache-tomcat-8.5.63/bin

./startup.sh

2.3.5、测试

2.4、tomcat8081配置

2.4.1、解压

tar -zxvf apache-tomcat-8.5.63.tar.gz

 2.4.2、在/opt/tomcat/tomcat8080/apache-tomcat-8.5.63/webapps/目录创建football文件夹

cd /opt/tomcat/tomcat8080/apache-tomcat-8.5.63/webapps/

mkdir football

2.4.3、上传index.html至football文件夹,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">足球8081!!!</p>
</body>
</html>

2.4.4、修改tomcat8081的端口信息

修改如下三个端口:
Server port、onnector port、redirectPort

2.4.5、启动tomcat8081

/opt/tomcat/tomcat8081/apache-tomcat-8.5.63/bin

./startup.sh

2.4.6、测试

2.5、Nginx配置

cd /usr/local/nginx/conf/

vim nginx.conf

# 修改内容如下:
server {
        listen       9001;
        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

 

2.6、测试

http://192.168.181.149:9001/basketball/index.html

http://192.168.181.149:9001/football/index.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值