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

发布时间:2022-04-24 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了详解nginx 配置多个tomcat共用80端口脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

场景:项目1放在tomcat1中,项目2放在tomcat2中,两个tomcat放在同一台服务器上,需要共享80端口访问

注意:这里和集群部署是不同的,集群部署是一个项目放在多个tomcat中。

这里通过nginx做反向代理,nginx请到http://nginx.org/en/download.html自行下载,

修改conf/nginx.conf中的server如下:

server { 
    listen    80; 
    server_name 192.168.1.197; 
 
    #charset koi8-r; 
 
    #access_LOG logs/host.access.log main; 
 
    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; 
    } 
@H_777_11@

好了,这时候就可以使用http://192.168.1.197/server1和http://192.168.1.197/server2分别访问服务了

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本宝典。

脚本宝典总结

以上是脚本宝典为你收集整理的详解nginx 配置多个tomcat共用80端口全部内容,希望文章能够帮你解决详解nginx 配置多个tomcat共用80端口所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。