我有一个nginx反向代理golang服务器,每个服务器都在自己的docker容器中并正常运行。当我尝试连接到Go容器时,我继续在nginx中收到此错误,在本地Mac机器和生产服务器Linux Debian上连接。它在一周前在我的本地Mac机器上工作,突然间它不再了
nginx_1 | 2017/09/28 01:29:54 [error] 5#5: *12 upstream timed out (110: Connection timed out) while connecting to upstream, client: 172.23.0.1, server: , request: "GET /api/about HTTP/1.1", upstream: "http://67.199.248.12:8080/api/about", host: "localhost"
有人可以解释这里发生了什么吗?什么是67.199.248.12以及为什么Nginx不能ping /连接到Go容器?
这是Go容器
中/ etc / hosts里面的内容127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.23.0.5 31f4103f002c
这是我的nginx.conf
upstream gogo {
server go:8080 weight=10 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
location /api/ {
resolver 127.0.0.1 valid=30s;
proxy_pass http://gogo;
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;
}
}
我正在使用docker-compose v3来运行nginx和docker
nginx:
restart: always
image: nginx
volumes:
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "80:80"
command: /bin/bash -c "nginx -g 'daemon off;'"
go:
build:
context: ./api
expose:
- "8080"
depends_on:
- nginx
去代码:
func main() {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/api/about", About).Methods("GET")
log.Fatal(http.ListenAndServe(":8080", router))
}
答案 0 :(得分:0)
好像容器不能互相ping?
我看到两种可能性:
首先:确保每个容器都在同一个网络上
docker run --network=host ...
或创建网络
docker network create nginx_go
docker run --network=nginx_go ...
第二次:使用docker-compose
version: '3.3'
services:
nginx:
image: nginx
# others details like volumes...
server:
image: go