根據前端請求的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容器;