【发布时间】:2017-04-14 04:37:31
【问题描述】:
我对 nginx 还很陌生,我听说很多人都在谈论它。
我将它与 Node.JS、Mongo、Express 和 Angular 一起在 DigitalOcean 实例上运行。
我最近添加了一个 SSL,它最初是有效的。但是当我几天后返回时,我得到了一个 502 Bad Gateway。
我的配置真的很简单:
server {
listen 80;
server_name mydomain.com;
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/mydomain_com/ssl-bundle.crt;
ssl_certificate_key /etc/nginx/ssl/mydomain_com/mydomain.com.key;
# side note: only use TLS since SSLv2 and SSLv3 have had recent vulnerabilities
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
location / {
proxy_pass http://130.78.19.81:3000;
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;
}
}
有没有人觉得这有什么问题??????
这是我的 Express App.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);
【问题讨论】:
-
你检查过日志吗?
标签: node.js nginx nginx-location