详解nginx 配置多个tomcat共用80端口

a 夏天 提交于 2019-12-20 09:30:06

场景:项目1放在tomcat1中,项目2放在tomcat2中,两个tomcat放在同一台服务器上,需要共享80端口访问
注意:这里和集群部署是不同的,集群部署是一个项目放在多个tomcat中。
这里通过nginx做反向代理

修改conf/nginx.conf中的server如下:
server {
       listen 80;
       server_name 192.168.1.197;

       location / {
    root html;
    index index.html index.htm;
  }

#加下面的配置
  location /server1{
    proxy_pass http://192.168.1.197:8081/server1;  #主要是这里,这是tomcat1的端口和项目
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    client_max_body_size 100m;
    root html;
    index index.html index.htm;
  }

  location /server2{
    proxy_pass http://192.168.1.197:8082/server2;  #主要是这里,这是tomcat2的端口和项目</span>
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    client_max_body_size 100m;
    root html;
    index index.html index.htm;
  }
}
好了,这时候就可以使用http://192.168.1.197/server1和http://192.168.1.197/server2分别访问服务了

转载自http://www.jb51.net/article/116372.htm

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!