详解nginx 配置多个tomcat共用80端口
场景:项目1放在tomcat1中,项目2放在tomcat2中,两个tomcat放在同一台服务器上,需要共享80端口访问
注意:这里和集群部署是不同的,集群部署是一个项目放在多个tomcat中。
这里通过nginx做反向代理,nginx请到http://nginx.org/en/download.html自行下载,
修改conf/nginx.conf中的server如下:
server{
listen80;
server_name192.168.1.197;
#charsetkoi8-r;
#access_loglogs/host.access.logmain;
location/{
roothtml;
indexindex.htmlindex.htm;
}
#加下面的配置
location/server1{
proxy_passhttp://192.168.1.197:8081/server1;#主要是这里,这是tomcat1的端口和项目
proxy_set_headerHost$host;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
client_max_body_size100m;
roothtml;
indexindex.htmlindex.htm;
}
location/server2{
proxy_passhttp://192.168.1.197:8082/server2;#主要是这里,这是tomcat2的端口和项目
proxy_set_headerHost$host;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
client_max_body_size100m;
roothtml;
indexindex.htmlindex.htm;
}
好了,这时候就可以使用http://192.168.1.197/server1和http://192.168.1.197/server2分别访问服务了
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。