Docker Nginx无法反向代理多个SpringBoot

环境

现在Docker上运行三个容器,其中两个容器为SpringBoot应用(jar包方式运行),另外一个为Nginx容器。
Nginx配置文件:

server {
    listen 80;
    server_name a.com;
    
    # Gzip Compression 
    gzip on;
    gzip_comp_level 9;
    gzip_min_length    256;
    gzip_disable "msie6";
    gzip_buffers 32 4k;
    gzip_http_version 1.0;
    gzip_proxied any;
    gzip_vary on;
    gzip_types application/atom+xml application/javascript
        application/json
        application/ld+json
        application/manifest+json
        application/rss+xml
        application/vnd.geo+json
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/x-web-app-manifest+json
        application/xhtml+xml
        application/xml
        font/opentype
        image/bmp
        image/svg+xml
        image/x-icon
        text/cache-manifest
        text/css
        text/plain
        text/vcard
        text/vnd.rim.location.xloc
        text/vtt
        text/x-component
        application/octet-stream
        text/x-cross-domain-policy;
        
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
    
        proxy_pass http://172.16.222.23:8101;
        proxy_redirect off;
    }
}

server {
    listen 80;
    server_name b.com;

    # Gzip Compression
    gzip on;
    gzip_comp_level 9;
    gzip_min_length    256;
    gzip_disable "msie6";
    gzip_buffers 32 4k;
    gzip_http_version 1.0;
    gzip_proxied any;
    gzip_vary on;
    gzip_types application/atom+xml application/javascript
        application/json
        application/ld+json
        application/manifest+json
        application/rss+xml
        application/vnd.geo+json
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/x-web-app-manifest+json
        application/xhtml+xml
        application/xml
        font/opentype
        image/bmp
        image/svg+xml
        image/x-icon
        text/cache-manifest
        text/css
        text/plain
        text/vcard
        text/vnd.rim.location.xloc
        text/vtt
        text/x-component
        application/octet-stream
        text/x-cross-domain-policy;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://172.16.222.23:8102;
        proxy_redirect off;
    }
}

问题描述

SpringBoot两个容器里都是同一个镜像来的,然后重启Nginx以后,a.com是可以访问的,而访问b.com时ngixn直接报502错误,请求各位大神有什么头绪吗? 谢谢

阅读 2.2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题