Nginx--反向代理配置

示例1

实现效果:在浏览器输入www.test.com,跳转到tomcat主页面。

Mac下hosts位置:

/etc/hosts

配置ip域名映射:
在这里插入图片描述

修改Nginx配置文件nginx.conf:
在这里插入图片描述
监听端口改为80,配置一个转发路径,转发到本机tomcat。

重新加载Nginx:

sudo nginx -s reload

启动tomcat,在浏览器访问www.test.com:

自动跳转到tomcat欢迎页面:
在这里插入图片描述

示例2

实现效果:使用Nginx反向代理,根据访问的路径跳转到不同端口的服务中,Nginx监听端口为9001.

访问http://localhost:9001/edu/ 跳转到127.0.0.1:8080
访问http://localhost:9001/vod/ 跳转到127.0.0.1:8082

准备两个tomcat:

  • tomcat9端口为8082
  • tomcat8端口为8080

准备两个html文件:
第一个放在tomcat9中:
webapps/edu/a.html:
在这里插入图片描述

第二个放在tomcat8中:
webapps/vod/a.html:
在这里插入图片描述

扫描二维码关注公众号,回复: 8847617 查看本文章

修改Nginx配置文件nginx.conf:
在这里插入图片描述

启动Nginx和两个tomcat:

浏览器输入:localhost:9001/edu/a.html

在这里插入图片描述
浏览器输入:localhost:9001/vod/a.html
在这里插入图片描述

发布了674 篇原创文章 · 获赞 1904 · 访问量 24万+

猜你喜欢

转载自blog.csdn.net/cold___play/article/details/104082163