Home > Enterprise >  Site NGINX not working error show 504 Gateway Time-out
Site NGINX not working error show 504 Gateway Time-out

Time:05-06

I have purchased AWS linux 2 server to host My Web application

I have published My Web node js application and want to run on default IP

I have configured the below things in /etc/nginx/sites-available/migrate.test.com

# the IP(s) on which your node server is running. I chose port 3000.
upstream migrate.test.com {
    server privateIPaddress:3000;
    keepalive 8;
}

# the nginx server instance
server {
    listen 80;
    listen [::]:80;
    server_name migrate.test.com;
    access_log /var/log/nginx/migrate.test.com.log;

    # pass the request to the node.js server with the correct headers
    # and much more can be added, see nginx config options
    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;
      proxy_read_timeout 3600;
      proxy_pass http://migrate.test.com/;
      proxy_redirect off;
    }
 }


```````

**My app.js code** 
```````
var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(3000, "privateIPaddress");
console.log('Server running success');

``````


please check by browser output 
[output][1]


  [1]: https://i.stack.imgur.com/1BD5X.png

CodePudding user response:

Specify the port 3000 that your node application is listening on as well, since the default is 80 for http -

proxy_pass http://migrate.test.com:3000;

Also, if your nginx server is running on the same machine as your node application server, you can also do -

proxy_pass http://localhost:3000;

https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

  • Related