【发布时间】: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 ...