簡體   English   中英

如何在AWS ECS上的同一任務定義中運行Nginx和Node

[英]How to run nginx and node in same Task Definition on AWS 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服務器嗎?

您可以嘗試將links作為node-container-name:www-development-node放入Nginx容器定義的網絡設置部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM