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