【发布时间】:2020-10-31 14:00:55
【问题描述】:
注意:我已经尝试过官方Nuxt/Nginx config,但没有任何运气。 我不断收到此错误
2020/07/10 18:41:57 [error] 6#6: *11 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.96.1, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "localhost"
当我使用proxy_pass http://127.0.0.1:3000、proxy_pass http://localhost:3000 或proxy_pass http://0.0.0.0:3000时
当我尝试将该条目更改为 proxy_pass http://container_name:3000 时,我收到一个新错误
2020/07/10 14:16:58 [emerg] 1#1: host not found in upstream "container_name" in /etc/nginx/conf.d/app.conf:25
我的 docker-compose.yml 文件如下所示:
version: '3'
networks:
nuxtnet:
services:
nuxt:
image: node
container_name: nuxt
volumes:
- ./client/:/var/www/html/client/
working_dir: /var/www/html/client/
environment:
- HOST=0.0.0.0
- PORT=3000
command: npm run dev
nginx:
image: nginx
container_name: nginx
ports:
- 80:80
volumes:
- ./client/:/var/www/html/client/
- ./config/nginx/conf.d/:/etc/nginx/conf.d/
- ./nginx/logs/:/var/log/nginx/
depends_on:
- nuxt
networks:
- nuxtnet
我的app.conf nginx 文件如下所示:
map $sent_http_content_type $expires {
"text/html" epoch;
"text/html; charset=utf-8" epoch;
default off;
}
server {
listen 80; # the port nginx is listening on
server_name myapp.dev; # setup your domain here
gzip on;
gzip_types text/plain application/xml text/css application/javascript;
gzip_min_length 1000;
location / {
expires $expires;
proxy_redirect off;
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_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 1m;
proxy_connect_timeout 1m;
proxy_pass http://localhost:3000; # set the address of the Node.js instance here
}
}
在运行 docker-compose up 和该项目的另一个副本运行 PHP 和 MySQL 时,这个流程无缝但在这个项目上我得到一个默认的 Nginx 错误支付 502 Bad Gateway 无论我在 @ 中放置什么987654333@ nginx 配置字段。请帮助我提出任何可以让这场噩梦消失的想法。提前致谢。
【问题讨论】:
-
服务名称是
nuxt,使用http://nuxt:3000,你确定它们在同一个网络中吗? -
那个给我一个错误
2020/07/10 19:29:13 [emerg] 1#1: host not found in upstream "nuxt" in /etc/nginx/conf.d/app.conf:25 -
码头网络 ls ?
-
我使用的是桥接网络
标签: docker nginx docker-compose nuxt.js