macos - Docker nginx connect() failed (113: Host is unreachable) while connecting to upstream
问题描述
I'm on a Macbook M1 and I have a problem with nginx (it looks like everything works fine for Ubuntu). I got "Host is unreachable" error in the console and "502 Bad Gateway" in the browser (localhost:8080 or localhost:8081). I'm using Docker 3.6.0
Any idea how to fix it?
my nginx.conf
worker_processes 4;
events { worker_connections 1024; }
http {
sendfile on;
client_max_body_size 25M;
upstream docker-platform-ui {
server platform-ui:8080;
}
upstream docker-web-platform {
server web-platform:3000;
}
upstream docker-management-console-ui {
server management-console-ui:5000;
}
upstream docker-document_console {
server document-console:4000;
}
server {
listen 8080;
location ~ \/(admin*|api|webhook) {
proxy_pass http://docker-web-platform;
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-Host $server_name;
}
location / {
proxy_pass http://docker-platform-ui/;
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-Host $server_name;
proxy_read_timeout 24h;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
server {
listen 8081;
location ~ \/(admin*|api|webhook) {
proxy_pass http://docker-web-platform;
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-Host $server_name;
proxy_read_timeout 24h;
proxy_set_header Connection '';
proxy_http_version 1.1;
chunked_transfer_encoding off;
}
location / {
proxy_pass http://docker-management-console-ui/;
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-Host $server_name;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
}
I got the errors:
2021/09/14 19:06:04 [error] 35#35: *1 connect() failed (113: Host is unreachable) while connecting to upstream, client: 172.21.0.1, server: , request: "GET / HTTP/1.1", upstream: "http://172.21.0.6:8080/", host: "localhost:8080"
reverse-proxy_1 | 172.21.0.1 - - [14/Sep/2021:19:06:04 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36"
reverse-proxy_1 | 2021/09/14 19:06:07 [error] 35#35: *1 connect() failed (113: Host is unreachable) while connecting to upstream, client: 172.21.0.1, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://172.21.0.6:8080/favicon.ico", host: "localhost:8080", referrer: "http://localhost:8080/"
reverse-proxy_1 | 172.21.0.1 - - [14/Sep/2021:19:06:07 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://localhost:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36"
EDIT: docker-compose.yml
version: '3'
services:
ngrok:
image: shkoliar/ngrok:latest
ports:
- 4551:4551
links:
- web-platform
environment:
- DOMAIN=web-platform
- PORT=3000
db:
image: postgres:11.5
ports:
- "5432:5432"
volumes:
- ./tmp/db:/var/lib/postgresql/data
redis:
image: 'redis:alpine'
volumes:
- 'redis:/data'
ports:
- "6379:6379"
mailcatcher:
image: 'schickling/mailcatcher'
ports:
- "1080:1080"
sidekiq:
image: web-platform:latest
depends_on:
- redis
volumes:
- ../../web-platform:/web-platform
command: sidekiq
env_file:
- web-platform/.env
web-platform:
image: web-platform:latest
depends_on:
- db
- redis
volumes:
- ../../web-platform:/web-platform
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s"
env_file:
- web-platform/.env
ports:
- "3000:3000"
- "8808:8808"
tty: true
stdin_open: true
document-console:
image: document-console:latest
depends_on:
- redis
# need to remove volum for production mode, since Docker user operates with puppeteer and doesn't have permition to work with any directories
# use volume only for nodemon for hot code reload in develop-local env
volumes:
- ../../document-console:/document-console
command: yarn debug
env_file:
- document-console/.env
ports:
- "4000:4000"
- "9229:9229"
privileged: true
# auditor:
# build:
# context: "../auditor"
# volumes:
# - ../auditor:/auditor
# command: ./run.sh
platform-ui:
image: platform-ui:latest
volumes:
- ../../platform-ui:/platform-ui
command: yarn start
env_file:
- platform-ui/.env
management-console-ui:
image: management-console-ui:latest
volumes:
- ../../management-console-ui:/management-console-ui
command: yarn start
ports:
- "5000:5000"
env_file:
- management-console-ui/.env
reverse-proxy:
image: reverse-proxy:latest
depends_on:
- platform-ui
- management-console-ui
ports:
- "8080:8080"
- "8081:8081"
# qa-automation:
# image: qa-automation:latest
# volumes:
# - ../../qa-automation:/qa-automation
volumes:
redis:
postgres:
解决方案
推荐阅读
- asp.net - IIS - dotnetcore - 混合模式应用程序的应用程序池未启动
- java - 为 org.springframework.core.io.Resource 对象分配名称
- android - ExoPlayer 谷歌图书馆集成
- excel - 在工作表excel中自动加载插件调用vba
- ios11 - 新的 Crashlytics 方法
- maven - maven 3.6.2 mvn help:系统报告错误
- java - 使用 JAVA 8 流从 JSON 文件中提取 JSON 对象
- angular - 无法在 NGINX 上访问没有斜杠的 URL
- internet-explorer-11 - 十六进制字符“1f40”出现在 Internet Explorer 11 的网页顶部
- python - Elasticsearch DSL Filter