title: 504 Gateway Time-out nginx/1.4.6 (Ubuntu) in Node.js and nginx
body: <p>I am testing a sample node app using nginx. </p>
  
  <p>But I get 504 Gateway Time-out. nginx/1.4.6 (Ubuntu 14.04)</p>
  
  <p>I saw others posts related to the same topic but its of no use.</p>
  
  <p>Below is the procedure which I followed for installing node, nginx on Azure.</p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>app.js file</strong></p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>sudo nano /etc/nginx/sites-available/default file</strong></p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>http port 80 is opened in azure dashboard</strong></p>
  
  <p><a href="https://i.stack.imgur.com/aTiS4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aTiS4.png" alt="enter image description here"></a></p>
  
  <p>So after all configurations trying to run <a href="http://13.65.148.35/" rel="nofollow noreferrer">http://13.65.148.35/</a> or testingnode.cloudapp.net will give 504 timeout.</p>
  
  <p>Please let me if anything needs to be configured for running node with nginx.</p>