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