【发布时间】:2018-06-12 16:02:48
【问题描述】:
我创建了一个Dockerrun.aws.json 文件,该文件定义了我想使用 AWS Elastic Beanstalk 运行的两个 Docker 映像。一个是 nginx 容器,带有静态前端网站和 API 路由,另一个是后端 API。但由于某种原因,容器链接不起作用,nginx 容器无法将请求转发到 API。
每当 nginx 尝试 proxy_pass 请求时,我都会收到此错误:
2018/01/02 22:03:01 [error] 5#5: *22 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.1.70, server: localhost, request: "POST /api/auth/login HTTP/1.1", upstream: "http://172.17.0.2:5000/api/auth/login", host: "my-app-dev.us-west-2.elasticbeanstalk.com", referrer: "http://my-app-dev.us-west-2.elasticbeanstalk.com/login"
从this aws multi-container documentation 看来,链接似乎是自动生成的?
这是我的 nginx 文件:
server {
listen 4000;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
# Matches any request with a file extension. Adds cache headers.
location ~ .*\..* {
try_files $uri =404;
expires 1y;
access_log off;
add_header Cache-Control "public";
}
# Matches api requests and redirects to the api server's port.
location /api {
proxy_pass http://api:5000;
}
# Any route that doesn't have a file extension. This helps react router route page urls using index.html.
location / {
try_files $uri $uri/ /index.html;
}
}
还有我的Dockerrun.aws.json 文件:
{
"AWSEBDockerrunVersion": "2",
"containerDefinitions": [
{
"name": "proxy",
"image": "my-app/proxy:1",
"essential": true,
"memory": 64,
"portMappings": [
{
"hostPort": 80,
"containerPort": 4000
}
],
"links": [
"api"
]
},
{
"name": "api",
"image": "my-app/api:1",
"essential": true,
"memory": 128
}
]
}
同样的设置在本地与 docker-compose 一起工作,但我尝试使用 aws 的方式显然不正确。
【问题讨论】:
标签: amazon-web-services docker nginx amazon-elastic-beanstalk