简体   繁体   中英

504 Gateway Time-out nginx/1.4.6 (Ubuntu) in Node.js and nginx

I am testing a sample node app using nginx.

But I get 504 Gateway Time-out. nginx/1.4.6 (Ubuntu 14.04)

I saw others posts related to the same topic but its of no use.

Below is the procedure which I followed for installing node, nginx on Azure.

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install -y build-essential
curl -Lo hello.js http://do.co/node-hello
sudo nano app.js

app.js file

var http = require('http');
http.createServer(function (req, res) {
  console.log('Came here');
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8080, 'localhost');
console.log('Server running at http://localhost:8080/');


ls -l
-rwxrwxrwx 1 root root 265 Mar 12 15:52 app.js

sudo npm install pm2 -g
pm2 startup
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup upstart -u azureuser --hp /home/azureuser

pm2 start app.js


Nginx Server
sudo apt-get update
sudo apt-get install nginx
sudo nano /etc/nginx/sites-available/default

sudo nano /etc/nginx/sites-available/default file

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.html index.htm; 

    server_name testingnode.cloudapp.net;

    location / {
        proxy_pass http://13.65.148.35:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

sudo service nginx restart

http port 80 is opened in azure dashboard

在此处输入图片说明

So after all configurations trying to run http://13.65.148.35/ or testingnode.cloudapp.net will give 504 timeout.

Please let me if anything needs to be configured for running node with nginx.

In your nginx config, change the line proxy_pass http://13.65.148.35:8080; to proxy_pass http://127.0.0.1:8080;

You're providing the externally accessible IP to the proxy pass, so nginx will conform to the firewall settings in the same way that an external user would; that is, not be able to access port 8080. Make sure it's communicating within the local scope of the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM