当有2个连续连接时,运行NodeJS的NGINX会抛出Bad Gateway

时间:2015-10-03 22:23:35

标签: node.js api nginx

我有一台运行NodeJS的NGINX服务器,每次有2个以上的用户同时访问同一个API端点时,它会不断抛出502 Bad Gateway

错误日志显示

*2 connect() failed (111: Connection refused) while connecting to upstream, client: 212.243.230.218, server: simplyask, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:3000/favicon.ico"

该应用程序基本上是一个客户端每隔几秒钟发送一次POST请求,当我通过浏览器同时执行G​​ET请求时,它会抛出该错误,任何其他时间它都能正常工作。

配置文件中是否有设置我不知道是不是允许这样做,或者我只是用太多的请求来杀死它(实际上不是那么多,每隔5秒左右只有1个)?< / p>

这就是我的app.js的样子:

var express = require('express');
var path = require('path');
var favicon = require('static-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/myApp', function(err) {
    if(err) {
        console.log('connection error', err);
    } else {
        console.log('connection successful');
    }
});

var app = express();

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use(favicon());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

...

和我的NGINX配置文件:

user www-data;
worker_processes 1;
pid /run/nginx.pid;

events {
    worker_connections 1024;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    ...

0 个答案:

没有答案