用于nginx /节点设置的502坏网关

时间:2016-03-03 07:24:57

标签: node.js express nginx forever linode

一直在个人网站上工作,经过一系列的更改后,他们将它们发送到服务器,并且从那里开始变坏了。

它在节点版本0.10.25上使用Express,在linode VPS上使用nginx,从Let's Encrypt使用SSL,并通过Forever运行应用程序。

我已经尝试停止并重新启动nginx,但使用`sudo server nginx'以及直接终止进程。尝试杀死/重新启动Forever中的所有商家信息。不太确定我做了什么。

错误日志:

2016/03/02 23:02:29 [error] 29775#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 67.180.44.115, server: example.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:4000/", host: "example.com"
2016/03/02 23:02:29 [error] 29775#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 67.180.44.115, server: example.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:4000/favicon.ico", host: "example.com", referrer: "https://example.com/"
2016/03/02 23:08:38 [error] 29917#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 67.180.44.115, server: example.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:4000/", host: "example.com"
2016/03/02 23:08:39 [error] 29917#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 67.180.44.115, server: example.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:4000/favicon.ico", host: "example.com", referrer: "https://example.com/"

网站的nginx conf

server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name example.com www.example.com;
    access_log /srv/www/theresa-bradley/logs/access.log;
    error_log /srv/www/theresa-bradley/logs/error.log;
    root /srv/www/theresa-bradley/dist;
    error_page 404 /srv/www/theresa-bradley/dist/error.html;
    error_page 500 /srv/www/theresa-bradley/dist/error.html;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

    location / {
        proxy_pass http://localhost:4000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
    }
}

app.js文件

'use strict';

var express = require('express');
var compress = require('compression');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var db = require('./db/db');
var routes = require('./src/routes/index');

var app = express();
app.enable('trust proxy');
app.use(compress());
app.locals.pretty = false;

// view engine setup
app.set('views', path.join(__dirname, 'src/views'));
app.set('view engine', 'jade');

if (app.get('env') === 'development') {
    app.use(favicon(__dirname + '/src/images/bookmarks/favicon.ico'));
} else {
    app.use(favicon(__dirname + '/dist/favicon.ico'));
}

app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended: false
}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'dist')));

app.use('/', routes);

// catch 404 and forward to error handler
app.use(function (req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});


// db setup
// db.connect('mongodb://localhost:27017/tbwedding', function (err) {
//     if (err) {
//         console.error('Unable to connect to Mongo.', err);
//         process.exit(1);
//     } else {
//         app.listen(4000, function () {
//             console.log('Listening on port 27017...');
//         });
//     }
// });


// ******************************************
//              error handlers
// ******************************************

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
    app.use(function (err, req, res, next) {
        res.status(err.status || 500);
        res.render('error', {
            message: err.message,
            error: err
        });
    });
}

// production error handler
// no stacktraces leaked to user
app.use(function (err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
        message: err.message,
        error: {}
    });
});
module.exports = app;

bin / www file

#!/usr/bin/env node
'use strict';

var app = require('../app');
var debug = require('debug')('theresa-bradley:server');
var http = require('http');

// forward declarations
var port;
var server;


// normalize a port into a number, string, or false
var normalizePort = function (val) {

    var port = parseInt(val, 10);

    if (isNaN(port)) {
        // named pipe
        return val;
    }

    if (port >= 0) {
        // port number
        return port;
    }

    return false;
};

// event listener for HTTP server "error" event
var onError = function (error) {
    if (error.syscall !== 'listen') {
        throw error;
    }

    var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port;

    // handle specific listen errors with friendly messages
    switch (error.code) {
        case 'EACCES':
            console.error(bind + ' requires elevated privileges');
            process.exit(1);
            break;
        case 'EADDRINUSE':
            console.error(bind + ' is already in use');
            process.exit(1);
            break;
        default:
            throw error;
    }
};

// event listener for HTTP server "listening" event
var onListening = function () {
    var addr = server.address();
    var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
    debug('Listening on ' + bind);
};


port = normalizePort(process.env.PORT || '4000');
app.set('port', port);

server = http.createServer(app);
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

永远的终端输出

$: forever start bin/www
    warn:    --minUptime not set. Defaulting to: 1000ms
    warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
    info:    Forever processing file: bin/www
$: forever list
    info:    Forever processes running
    data:        uid  command         script  forever pid   id logfile                         uptime
    data:    [0] AP0I /usr/bin/nodejs bin/www 29999   30001    /home/bradley/.forever/AP0I.log STOPPED

看到另一个SO问题,他们询问netstat,所以我看了一下(但我不确定输出是什么意思,所以对我个人而言并不重要)

$: sudo netstat -pantu
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      2909/php5-cgi
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      29916/nginx.conf
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2866/sshd
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      3019/master
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      29916/nginx.conf
tcp        0    224 *.*.*.*:22      *.*.*.*:49426     ESTABLISHED 28650/sshd: bradley
tcp6       0      0 :::22                   :::*                    LISTEN      2866/sshd
tcp6       0      0 :::25                   :::*                    LISTEN      3019/master
udp        0      0 0.0.0.0:46993           0.0.0.0:*                           2520/dhclient
udp        0      0 0.0.0.0:68              0.0.0.0:*                           2520/dhclient
udp        0      0 173.255.249.134:123     0.0.0.0:*                           3304/ntpd
udp        0      0 127.0.0.1:123           0.0.0.0:*                           3304/ntpd
udp        0      0 0.0.0.0:123             0.0.0.0:*                           3304/ntpd
udp6       0      0 fe80::f03c:91ff:fe6:123 :::*                                3304/ntpd
udp6       0      0 2600:3c01::f03c:91f:123 :::*                                3304/ntpd
udp6       0      0 ::1:123                 :::*                                3304/ntpd
udp6       0      0 :::123                  :::*                                3304/ntpd
udp6       0      0 :::61715                :::*                                2520/dhclient

0 个答案:

没有答案