一、该问题的重现步骤是什么?
1. 服务器上部署BladeX,看到服务成功注册到nacos
2. 用postman访问88端口去访问user服务
3.返回502Bad Gateway
二、你期待的结果是什么?实际看到的又是什么?
期待结果:成功访问到后台服务
实际看到:返回502 Bad Gateway
三、你正在使用的是什么产品,什么版本?在什么操作系统上?
BladeX,2.5.0.RELEASE,在centos8
四、请提供详细的错误堆栈信息,这很重要。
查看了docker_blade-nginx_1服务的日志,报代理错误,一开始upstream是172.30.0.81和172.30.0.82,报错之后我换成了服务器地址+8001和8002端口
2020/06/12 15:14:48 [error] 67#67: *10 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.197.2.231, server: gateway, request: "GET /blade-user/page?current=1&size=10&deptId= HTTP/1.1", upstream: "http://10.197.0.130:8001/blade-user/page?current=1&size=10&deptId=", host: "10.197.0.130:88" 2020/06/12 15:14:48 [warn] 67#67: *10 upstream server temporarily disabled while reading response header from upstream, client: 10.197.2.231, server: gateway, request: "GET /blade-user/page?current=1&size=10&deptId= HTTP/1.1", upstream: "http://10.197.0.130:8001/blade-user/page?current=1&size=10&deptId=", host: "10.197.0.130:88" 2020/06/12 15:14:48 [error] 67#67: *10 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.197.2.231, server: gateway, request: "GET /blade-user/page?current=1&size=10&deptId= HTTP/1.1", upstream: "http://10.197.0.130:8002/blade-user/page?current=1&size=10&deptId=", host: "10.197.0.130:88" 2020/06/12 15:14:48 [warn] 67#67: *10 upstream server temporarily disabled while reading response header from upstream, client: 10.197.2.231, server: gateway, request: "GET /blade-user/page?current=1&size=10&deptId= HTTP/1.1", upstream: "http://10.197.0.130:8002/blade-user/page?current=1&size=10&deptId=", host: "10.197.0.130:88"
五、若有更多详细信息,请在下面提供。
运行的容器有
7e37d01e856c 10.197.0.130/blade/blade-user:2.5.0.RELEASE "java -Djava.securit…" About an hour ago Up About an hour 8102/tcp docker_blade-user_1 783f161b9104 10.197.0.130/blade/blade-equipment:2.5.0.RELEASE "java -Djava.securit…" About an hour ago Up About an hour 9014/tcp docker_blade-equipment_1 f91b111cfa6e 10.197.0.130/blade/blade-system:2.5.0.RELEASE "java -Djava.securit…" About an hour ago Up About an hour 8106/tcp docker_blade-system_1 c1bbb34bf29d 10.197.0.130/blade/blade-gateway:2.5.0.RELEASE "java -Djava.securit…" About an hour ago Up About an hour 80/tcp, 0.0.0.0:8001->8001/tcp docker_blade-gateway1_1 220dc75af8f9 10.197.0.130/blade/blade-resource:2.5.0.RELEASE "java -Djava.securit…" About an hour ago Up About an hour 8010/tcp docker_blade-resource_1 e7848e48e35a 10.197.0.130/blade/blade-xxljob:2.5.0.RELEASE "java -Djava.securit…" About an hour ago Up About an hour 7008/tcp docker_blade-xxljob_1 fd52c3046c56 10.197.0.130/blade/blade-auth:2.5.0.RELEASE "java -Djava.securit…" About an hour ago Up About an hour 8100/tcp docker_blade-auth1_1 f80d559189cf 10.197.0.130/blade/blade-gateway:2.5.0.RELEASE "java -Djava.securit…" About an hour ago Up About an hour 80/tcp, 0.0.0.0:8002->8002/tcp docker_blade-gateway2_1 0ff8a4a1479f 10.197.0.130/blade/blade-xxljob-admin:2.5.0.RELEASE "java -Djava.securit…" About an hour ago Up About an hour 0.0.0.0:7009->7009/tcp docker_blade-xxljob-admin_1 2ccfbc49508e 10.197.0.130/blade/blade-auth:2.5.0.RELEASE "java -Djava.securit…" About an hour ago Up About an hour 8100/tcp docker_blade-auth2_1 1cdf1c8c3f0f 10.197.0.130/blade/blade-log:2.5.0.RELEASE "java -Djava.securit…" About an hour ago Up About an hour 8103/tcp docker_blade-log_1 004dd30df8f4 seataio/seata-server:1.1.0 "java -Djava.securit…" About an hour ago Up About an hour 0.0.0.0:8091->8091/tcp docker_seata-server_1 ae8f07731d65 nginx:stable-alpine-perl "nginx -g 'daemon of…" About an hour ago Up About an hour 80/tcp, 0.0.0.0:8000->8000/tcp docker_web-nginx_1 e3acc3d3c6ff nacos/nacos-server:1.1.4 "bin/docker-startup.…" About an hour ago Up About an hour 0.0.0.0:8848->8848/tcp docker_nacos_1 ddcac666212e nginx:stable-alpine-perl "nginx -g 'daemon of…" About an hour ago Up 44 minutes 80/tcp, 0.0.0.0:88->88/tcp docker_blade-nginx_1 0875104fae4b bladex/sentinel-dashboard:1.7.1 "java -Djava.securit…" About an hour ago Up About an hour 8719/tcp, 0.0.0.0:8858->8858/tcp docker_sentinel_1 4c63bd41a22c redis:5.0.8-alpine "docker-entrypoint.s…" About an hour ago Up About an hour 0.0.0.0:3379->6379/tcp docker_blade-redis_1
我的BladeX根目录的docker-compose.yml, 后端网关以及gateway的配置
blade-gateway: image: "${REGISTER}/blade/blade-gateway:${TAG}" ports: - 80:80 networks: blade_net: ipv4_address: 10.197.0.130 后端网关的配置 #负载均衡服务器设置 upstream gateway { server 172.30.0.81; server 172.30.0.82; } #该服务器接受到端口88的所有流量并将其传递给上游upstream 。 #请注意,upstream名称和proxy_pass需要匹配。 server { listen 88; server_name gateway; #代理设置 location / { #把原http请求的Header中的Host字段也放到转发的请求里 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_buffering off; proxy_pass http://gateway; } } gateway的配置 blade-gateway1: image: "${REGISTER}/blade/blade-gateway:${TAG}" environment: - TZ=Asia/Shanghai privileged: true restart: always ports: - 8001:8001 blade-gateway2: image: "${REGISTER}/blade/blade-gateway:${TAG}" environment: - TZ=Asia/Shanghai privileged: true restart: always ports: - 8002:8002
看来你对这里面好多东西都不怎么理解,下面这段可以作为辅助,你再好好跟着文档做一遍,很多人已经成功了,所以文档和配置肯定没问题的。
一、首先部署Gateway的两个服务,设定ip为 172.30.0.81 和 172.30.0.82 ,因为都是子网调用,所以不需要对外映射端口(nginx默认80端口,你的映射8001:8001也完全是错的)
二、nginx配置文件配置反向代理,配置81和82的两个gateway服务
三、注意要把这个配置文件正确挂载到nginx的容器服务
四、使用启动脚本拷贝配置文件到设定好的位置
五、依次启动脚本的命令,这样才算映射完毕
六、这里有很多基础的只是需要先了解,比如docker-compose,docker-compose组子网,docker端口映射,nginx反向地理配置等等,如果不了解的话做起来还是很吃力的
扫一扫访问 Blade技术社区 移动端