nginx 根据不同url转发请求对应tomcat容器


根据前端请求的url,nginx转发到指定的tomcat容器

原理如图:

现在我们有2个tomcat,一个tomcat的端口为9001,另一个tomcat的端口为9002

1.找到nginx的配置文件nginx.conf,在server标签中进行修改;

location /sass/ {
   proxy_pass http://127.0.0.1:9001/sass/;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 }

location /regist/ {
   proxy_pass http://127.0.0.1:9002/regist/;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 }

2.根据前端输入的请求地址 http://localhost:9001/sass/  nginx转发找到对应9001tomcat容器;

3.根据输入的请求地址 http://localhost:9002/regist/   nginx转发找到对应9002tomcat容器;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM