0

We try to get a service running, with two containers in AWS ECS with FARGATE:

  1. node.js
  2. nginx serving static files and proxy traffic to node.js

The problem is, that the nginx is always starting faster then node.js. So the upstream is not ready. Because of that nginx crashes.

Here is my nginx config

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?

Duy Phan
  • 132
  • 7
tschiela
  • 5,231
  • 4
  • 28
  • 35
  • Possible duplicate of [Setup nginx not to crash if host in upstream is not found](https://stackoverflow.com/questions/32845674/setup-nginx-not-to-crash-if-host-in-upstream-is-not-found) – nebuler Feb 10 '19 at 01:44

1 Answers1

0

You can try to put links into network settings section of nginx container definition as node-container-name:www-development-node.

Duy Phan
  • 132
  • 7