我有设置
docker-compose:
nginx:
restart: always
build: nginx/. // loads nginx:alpine image + copies the config
ports:
- 80:80
- 1337:1337
links:
- rose:rose
rose:
build: rose/. // simple website, based on node:latest
restart: always
expose:
- 1337
nginx.conf:
upstream docker-rose {
server rose:1337;
}
server {
listen 0.0.0.0:1337;
gzip on; // + some other gzip crap
location ~ ^/(.*)/ {
proxy_pass http://docker-rose;
proxy_redirect off;
proxy_set_header Host $http_host; // + some other proxy headers thingy
}
}
docker-compose ps:
nginx_1 nginx -g daemon off; Up 0.0.0.0:1337->1337/tcp, 0.0.0.0:80->80/tcp
rose_1 npm start Up 1337/tcp
所以我希望 nginx 监听外部 1337 端口并通过 1337 内部端口将所有内容传递给 rose。
但是,当我在浏览器中打开 localhost:1337 时,我得到
nginx_1 | 2018/04/29 14:57:22 [错误] 9#9:*28 未找到“/etc/nginx/html/index.html”(2:没有此文件或目录),客户端:172.19.0.1,服务器:,请求:“GET / HTTP/1.1”,主机:“localhost:1337”
它有一项任务:将 everything_from_outside:1337 重定向到 internal_container:1337。它究竟为何尝试加载 /etc/nginx/html/index.html?
编辑:因此,我通过 获取了容器 ID,docker ps
并通过 登录docker exec -ti %id% sh
。尝试 ping rose:
/ # ping rose
PING rose (172.19.0.11): 56 data bytes
64 bytes from 172.19.0.11: seq=0 ttl=64 time=0.083 ms
64 bytes from 172.19.0.11: seq=1 ttl=64 time=0.116 ms
尝试 ping 本地主机的 1337 端口:
/ # ping localhost:1337
PING localhost:1337 (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.080 ms