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

2025-05-26 0 48

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

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

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

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

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33
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;

}

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

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

原文链接:http://blog.csdn.net/sinat_33388558/article/details/54572724

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 详解nginx 配置多个tomcat共用80端口 https://www.kuaiidc.com/53584.html

相关文章

发表评论
暂无评论