简体   繁体   English

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

[英]How to run nginx and node in same Task Definition on AWS ECS

We try to get a service running, with two containers in AWS ECS with FARGATE: 我们尝试运行服务,并在带有FARGATE的AWS ECS中使用两个容器:

  1. node.js 的node.js
  2. nginx serving static files and proxy traffic to node.js nginx将静态文件和代理流量提供给node.js

The problem is, that the nginx is always starting faster then node.js. 问题在于,nginx的启动总是比node.js快。 So the upstream is not ready. 因此上游尚未准备就绪。 Because of that nginx crashes. 因此,nginx崩溃了。

Here is my nginx config 这是我的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;
}

} }

Is there maybe a way nginx can ignore the absence of the node.js server until it is ready? 在准备就绪之前,nginx可能有办法忽略掉node.js服务器吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM