docker 中的 vue / nodejs 和 nginx:连接到上游时连接()失败(111:连接被拒绝)

vue / nodejs & nginx in docker: connect() failed (111: Connection refused) while connecting to upstream

目录结构:

myapp
-- frontend
---- docker
------ frontend
-------- nginx
-------- nginx.conf
docker-compose.yml

docker-compose.yml: https://pastebin.com/THxMf0xM (移动到 pastebin 以避免烦人的“主要是代码”错误)

default.conf:

server {
    listen 80;
    server_name localhost;
    root /var/www/html;

    location / {
        proxy_pass http://vue:8081;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

为什么我得到 connect() failed (111: Connection refused) while connecting to upstream

https://pastebin.com/THxMf0xM 行号 23,应该指向端口 80 即 ports: - '8081:80'

通过将 proxy_pass http://vue:8081; 更改为 proxy_pass http://vue:8080;

来修复

注意8080端口。

其次,重建前端服务

最后,从 vue 服务中删除 ports 选项

谢谢大家