连接到上游时出现 502 错误网关/失败(111:连接被拒绝)

连接到上游时出现 502 错误网关/失败(111:连接被拒绝)

我有以下 docker-compose xml

web:
  build: nginx/.
  container_name: nginx
  ports:
    - "80:80"
  links:
    - "openchain"
  restart: always
wallet:
  build: wallet/.
  container_name: wallet
  ports:
    - "81:81"
  restart: always
  read_only: false
  volumes:
    - ./www:/usr/share/nginx/html:rw
  working_dir: /user/share/nginx/html
openchain:
  build: openchain/.
  ports:
    - "8080"
  volumes:
    - ./data:/openchain/data
  restart: always

以下是分别针对网页和钱包的配置

worker_processes 4;

events { worker_connections 1024; }

http {
    server {
        listen 80;

        location / {
            proxy_pass http://127.0.0.1:8080/;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
}

工作进程 4;

事件 { worker_connections 1024; }

http {

server {
    listen 81;

    location / {
        root /usr/share/nginx/html;
    }
}

}

当我运行 docker ps 时我得到了

    05e351c8f8db        openchain_web         "nginx -g 'daemon off"   5 seconds ago       Up 5 seconds        0.0.0.0:80->80/tcp, 443/tcp    nginx
    e7401ea7c5bc        openchain_wallet      "nginx -g 'daemon off"   5 seconds ago       Up 5 seconds        80/tcp, 443/tcp,
0.0.0.0:81->81/tcp   wallet
    40439fdb1c69        openchain_openchain   "dotnet openchain.dll"   5 seconds ago       Up 5 seconds        0.0.0.0:32774->8080/tcp        openchain_openchain_1

但是当我尝试通过代理 openchain_web 访问端口 openchain_openchain 时,出现了主题错误

我是 docker 新手,所以我不确定我是否正确地使用 nginx 进行代理

你能告诉我我做错了什么吗?

PS 我可以正常访问钱包

答案1

我在 NGINX 配置中使用了这个配置,其中 appsrv 是 fastcgi 镜像的 docker-compose.yml 服务的名称

server {

    #listen 80 default_server;
    listen 80;
    #server_name xxxxxxxxx.com;
    index index.php index.html;
    root /var/www/html;

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info  ^(.+\.php)(/.+)$;
        fastcgi_index            index.php;
        fastcgi_pass             appsrv:9000;
        include                  fastcgi_params;
        fastcgi_param   PATH_INFO       $fastcgi_path_info;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    client_max_body_size 200M;

}

相关内容