【问题标题】:For no reason I can see I'm getting bad gateway我无缘无故地看到我的网关不好
【发布时间】: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


【解决方案1】:

似乎http://130.78.19.81 的服务器很可能正在使用防火墙限制阻止端口 3000 甚至可能是源 IP。

【讨论】:

  • 我运行了以下命令,并没有看到端口打开,但我的理解是应该是:deploy@OM:~$ sudo netstat -ntlp | grep LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1116/sshd tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 919/mongod tcp6 0 0 :::22 :::* LISTEN 1116/ sshd
  • 从您的原始帖子中不清楚您的架构是什么。节点应用程序是否与 NGINX 在同一台机器上运行?你在哪里运行你的 netstat 命令?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-10
  • 2012-09-06
  • 1970-01-01
  • 2018-08-17
相关资源
最近更新 更多