【问题标题】:Nginx 502 bad gateway, failed (101: Network unreachable while connecting to upstream). Inside DockerNginx 502 bad gateway, failed (101: Network unreachable while connected to upstream)。在 Docker 内部
【发布时间】:2021-04-22 23:27:24
【问题描述】:

所以我在端口 7001 上使用节点应用程序(100% 工作)的 docker 容器。我想从 localhost:8090 访问这个应用程序,但不幸的是我收到 502 bad gateway 错误。带有端口映射的 Docker 运行命令也可以正常工作。 nginx配置一定有错误。我很感激任何想法。 由于我的应用程序很少,我的 nginx 看起来像: nginx.conf:

user root;

worker_processes 2;

events {
  worker_connections 1024;
}

http {
  include mime.types;
  default_type application/octet-stream;

  sendfile on;

  keepalive_timeout 65;

  include /etc/nginx/sites-enabled/*;
}

daemon off;

导致问题的应用程序(/etc/nginx/sites-enabled/third-page):

server {
        listen      8090;
        root        /usr/bin;
        server_name localhost;
        access_log  /dev/null;
        error_log   /dev/null;

        location / {
                proxy_pass http://127.0.0.0:7001;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Fowarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Fowarded-Proto $scheme;
                proxy_cache_bypass $http_upgrade;

               try_files $uri $uri/ =404;
        }

        location ~ \.(gif) {
                root /var/lib;
        }

}

来自 error.log 的信息:

2021/01/18 16:07:14 [error] 744#744: *175 connect() to 127.0.0.0:7001 failed (101: Network unreachable) while connecting to upstream, client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.0:7001/", host: "localhost:8090", referrer: "http://localhost:8080/"

【问题讨论】:

  • 节点应用程序到底在哪里运行?
  • 节点应用程序位于 /usr/app.js 中,我从容器内部手动运行它 - 这更像是在学习 docker 和 nginx 时进行培训。我知道这在现实生活场景中是不好的解决方案。
  • 显示如何启动容器。 docker run ...

标签: docker nginx


【解决方案1】:

运行 netstat 并检查是否有任何东西在使用端口 7001 并将 proxy_pass 中的 http://127.0.0.0 更改为 http://127.0.0.1

【讨论】:

    猜你喜欢
    • 2021-03-07
    • 2017-04-18
    • 2016-03-26
    • 2020-08-01
    • 2015-07-25
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    • 2023-03-20
    相关资源
    最近更新 更多