Question

I got the following nginx config:

server {
    listen 80;
    server_name domainName.com;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/rss+xml text/javascript image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype;
    access_log /var/log/nginx/logName.access.log;
    location / {
        proxy_pass    http://127.0.0.1:9000/;
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    location ~ ^/(min/|images/|ckeditor/|img/|javascripts/|apple-touch-icon-ipad.png|apple-touch-icon-ipad3.png|apple-touch-icon-iphone.png|apple-touch-icon-iphone4.png|generated/|js/|css/|stylesheets/|robots.txt|humans.txt|favicon.ico) {
          root /root/Dropbox/nodeApps/nodeJsProject/port/public; 
          access_log off;
          expires max;
        }
}

It is proxy for node.js application on port 9000.

Is it possible to change this config to let nginx use another proxy url (on port 9001 for example) in case nginx got 504 error.

I need this in case when node.js server is down on port 9000 and need several seconds to restart automatically and several seconds nginx gives 504 error for every request. I want nginx to "guess" that node.js site on port 9000 is down and use reserve node.js site on port 9001

Was it helpful?

Solution

Use upstream module.

upstream node {
    server 127.0.0.1:9000;
    server 127.0.0.1:9001 backup;
}

server {
...
    proxy_pass http://node/;
...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top