【问题标题】:How to run nginx and node in same Task Definition on AWS ECS如何在 AWS ECS 上的同一任务定义中运行 nginx 和节点
【发布时间】:2019-07-03 20:28:35
【问题描述】:

我们尝试让服务运行,在 AWS ECS 中使用 FARGATE 中的两个容器:

  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 服务器的缺失,直到它准备好?

【问题讨论】:

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-28
    • 2016-05-04
    • 2019-06-08
    • 2020-10-04
    • 2023-02-06
    • 1970-01-01
    • 2019-09-25
    • 2017-03-04
    相关资源
    最近更新 更多