美文网首页
nginx笔记-反向代理实例

nginx笔记-反向代理实例

作者: Sunny_苏 | 来源:发表于2020-05-10 17:14 被阅读0次

准备工作

1 安装nginx,假设在虚拟机 ip为192.168.0.X的机器上

2.部署2个tomcat~

tomcat1 在172.10.0.1 ; 在根目录建一个文件夹 tomcat1 放一个html 起名字 test.html 内容输出tomcat1

tomcat2在 172.20.0.2; 在根目录建一个文件夹 tomcat2  放一个html 起名字 test.html 内容输出tomcat2

然后启动tomcat成功

修改nginx配置

在192.168.0.X的机器上找到 /usr/local/nginx/nginx.conf文件

修改一个server:

server{

    listen:80; //监听的nginx端口,默认为80可以在访问时候不假端口号;若修改需要加

    server_name  192.168.0.X;//即nginx虚拟机IP

    localtion  ~tomcat1{

        proxy_pass http:172.10.0.1:8080;

      }

     localtion  ~tomcat2{

        proxy_pass http:172.20.0.2:8080;

    }

}

然后重启nginx即可;

测试访问

http:192.168.0.X/tomcat1/test.html 页面输出 tomcat1

http:192.168.0.X/tomcat2/test.html  页面输出 tomcat2

相关文章

网友评论

      本文标题:nginx笔记-反向代理实例

      本文链接:https://www.haomeiwen.com/subject/ctujnhtx.html