服务器上的网关不良,但使用端口3000不在本地

时间:2016-12-04 18:14:01

标签: node.js express nginx digital-ocean bcrypt

我最近使用本教程为我的Node / Express / Angular项目实现了用户授权模型:https://devdactic.com/restful-api-user-authentication-1/

在我的本地计算机上运行它很有效,但是当我将它上传到我的数字海洋帐户时,到目前为止我已成功托管该项目,我收到了502 Bad Gateway错误。即使我使用直接IP地址和端口。

我在Ubuntu 14上运行它的MEAN实例,并在其他实例上运行其他网站。

我也在该实例上运行Nginx。

我只是不知道如何在我的" localhost:3000"本地运行应用程序。但是在VH上运行会让我拒绝连接。

我认为问题是" bcrypt"。由于某种原因,它导致了问题。

有没有人遇到这个以及有关调试的任何建议?

这是我在Nginx日志中看到的内容。据我所知,我没有在这台服务器上使用PHP,但我在那里看到了一个条目。

2016/12/05 02:16:47 [error] 10693#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 207.108.92.101, server: maybarry.com, request: "GET / HTTP/1.1", upstream: "http://132.64.19.81:3000/", host: "maybarry.com"
2016/12/05 02:16:50 [error] 10693#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 207.108.92.101, server: maybarry.com, request: "GET / HTTP/1.1", upstream: "http://132.64.19.81:3000/", host: "maybarry.com"
2016/12/05 02:17:11 [error] 10693#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 207.108.92.101, server: maybarry.com, request: "GET / HTTP/1.1", upstream: "http://132.64.19.81:3000/", host: "maybarry.com"
2016/12/05 02:28:37 [error] 10867#0: *4 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 207.108.92.101, server: maybarry.com, request: "POST /api/authenticate HTTP/1.1", upstream: "http://132.64.19.81:3000/api/authenticate", host: "maybarry.com", referrer: "http://maybarry.com/login"
2016/12/05 02:31:42 [error] 10867#0: *9 upstream prematurely closed connection while reading response header from upstream, client: 207.108.92.101, server: maybarry.com, request: "POST /api/signup HTTP/1.1", upstream: "http://132.64.19.81:3000/api/signup", host: "maybarry.com", referrer: "http://maybarry.com/register"
2016/12/05 10:27:48 [error] 12671#0: *4 upstream prematurely closed connection while reading response header from upstream, client: 207.108.92.101, server: maybarry.com, request: "POST /api/signup HTTP/1.1", upstream: "http://132.64.19.81:3000/api/signup", host: "maybarry.com", referrer: "http://maybarry.com/register"
2016/12/05 10:27:48 [error] 12671#0: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 207.108.92.101, server: maybarry.com, request: "POST /api/signup HTTP/1.1", upstream: "http://132.64.19.81:3000/api/signup", host: "maybarry.com", referrer: "http://maybarry.com/register"
2016/12/05 10:40:56 [error] 12983#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 207.108.92.101, server: maybarry.com, request: "GET /register HTTP/1.1", upstream: "http://132.64.19.81:3000/register", host: "maybarry.com"
2016/12/05 10:40:59 [error] 12983#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 207.108.92.101, server: maybarry.com, request: "GET /register HTTP/1.1", upstream: "http://132.64.19.81:3000/register", host: "maybarry.com"
2016/12/05 10:41:48 [error] 12983#0: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 195.154.181.162, server: maybarry.com, request: "GET /_file-manager/php/connector.php HTTP/1.1", upstream: "http://132.64.19.81:3000/_file-manager/php/connector.php", host: "maybarry.com", referrer: "http://maybarry.com/_file-manager/php/connector.php"

这是我的user.js文件。当我注释掉对bcrypt的引用时,一切正常。好吧,除了bcrypt方法。所以我知道这与它有关:

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var bcrypt = require('bcrypt');

// Thanks to http://blog.matoski.com/articles/jwt-express-node-mongoose/

// set up a mongoose model
var UserSchema = new Schema({
    name: {
        type: String,
        unique: true,
        required: true
    },
    password: {
        type: String,
        required: true
    },
    email:{
        type: String,
        required: true
    }
});

UserSchema.pre('save', function(next) {
    var user = this;
    if (this.isModified('password') || this.isNew) {
        bcrypt.genSalt(10, function(err, salt) {
            if (err) {
                return next(err);
            }
            bcrypt.hash(user.password, salt, function(err, hash) {
                if (err) {
                    return next(err);
                }
                user.password = hash;
                next();
            });
        });
    } else {
        return next();
    }
});

UserSchema.methods.comparePassword = function(passw, cb) {
    bcrypt.compare(passw, this.password, function(err, isMatch) {
        if (err) {
            return cb(err);
        }
        cb(null, isMatch);
    });
};

module.exports = mongoose.model('User', UserSchema);

0 个答案:

没有答案