如何在AWS ECS上的同一任务定义中运行nginx和node

时间:2019-02-09 23:50:48

标签: amazon-web-services docker nginx amazon-ecs

我们尝试使用具有FARGATE的AWS ECS中的两个容器来运行服务:

  1. node.js
  2. nginx提供静态文件并代理流量到node.js

问题是,nginx的启动总是比node.js快。因此上游尚未准备就绪。因此,nginx崩溃了。

这是我的Nginx配置

server {
listen       80;
server_tokens off;

auth_basic "closed website";
auth_basic_user_file authnginx/htpasswd;

add_header X-XSS-Protection "1; mode=block";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
add_header Strict-Transport-Security "max-age=86400; includeSubDomains";
add_header Referrer-Policy "strict-origin-when-cross-origin";
root /usr/share/nginx/html;
# gzip_static on;
# brotli_static on;

location = /status {
   access_log off;
   allow all;
   return 200 "healthy\n";
}

location / {
    try_files $uri @backend;
}

location @backend {
    proxy_pass http://www-development-node:3000;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # Following is necessary for Websocket support
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";

    proxy_connect_timeout 70;
}

location ~* .(ico|css|js|gif|jpg|jpeg|png|svg|eot|ttf|woff|woff2|mp4)$ {
    expires 365d;
    access_log off;
}

location ~ /\. {
    deny all;
    access_log off;
    log_not_found off;
}

}

在准备就绪之前,nginx是否有办法忽略node.js服务器的缺失?

1 个答案:

答案 0 :(得分:0)

您可以尝试将links作为node-container-name:www-development-node放入nginx容器定义的网络设置部分。