首页 文章

504 Node.js和nginx中的网关超时nginx / 1.4.6(Ubuntu)

提问于
浏览
1

我正在使用nginx测试一个示例节点应用程序 .

但我得到504网关超时 . nginx / 1.4.6(Ubuntu 14.04)

我看到其他与同一主题相关的帖子,但没有用 .

下面是我在Azure上安装node nginx时遵循的步骤 .

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

enter image description here

所以在尝试运行http://13.65.148.35/或testingnode.cloudapp.net的所有配置都会给出504超时 .

如果需要为nginx运行节点配置任何内容,请告诉我 .

1 回答

  • 2

    在你的nginx配置中,将行 proxy_pass http://13.65.148.35:8080; 更改为 proxy_pass http://127.0.0.1:8080;

    您正在为代理传递提供外部可访问的IP,因此nginx将以与外部用户相同的方式符合防火墙设置;也就是说,无法访问端口8080.确保它在服务器的本地范围内进行通信 .

相关问题