node.js - 将通知系统更改为 SSL。(目前在 Chrome 中使用 https 时会被阻止,因为使用的是 http)

标签 node.js curl https express

我的网站中有一个通知系统,我正在尝试将其从 http 更改为 https。

但是我的 app.js 现在正在列出端口 8888。

有没有快速修改的方法?网上试了好几​​种方法都不行。

(现在我的 curl 类似于http://myipaddress:8888)

非常感谢!我真的很感激。

    /* CONFIGURATION */

/* Web Server Config */
var _postpath = '/send';
var _listenport = 8888;
var _listenaddr = '0.0.0.0';  //use '0.0.0.0' to listen on all interfaces

/* Slave (sub) Redis Server Config */
var _channelfilter = '*';
var _sub_db_addr = '127.0.0.1';
var _sub_db_passwd_protected = true;
var _sub_db_passwd = 'mypassword';
var _sub_db_port = 6379;  //default redis port is 6379

/* Master (pub) Redis Server Config */
var _pub_db_addr = '127.0.0.1';
var _pub_db_passwd_protected = true;
var _pub_db_passwd = 'mypassword';
var _pub_db_port = 6379;  //default redis port is 6379

/* add pub.auth(_pub_db_passwd) in function to enable password


/* SocketIO Config */
var _loglevel = 1;

/* simple-pub-sub Config */
var _secretkey = "mypassword";


/* SERVER CODE -- DO NOT MODIFY */
redis = require('redis');
express = require('express');
socketio = require('socket.io');
fs = require("fs"),
pub = redis.createClient(_pub_db_port, _pub_db_addr); if (_pub_db_passwd_protected) {  }

sub = redis.createClient(_sub_db_port, _sub_db_addr); if (_sub_db_passwd_protected) { }
sub.on("pmessage", function(pattern, channel, json) { io.sockets.volatile.emit(channel, JSON.parse(json)); });
sub.psubscribe('*');

app = express.createServer(express.static(__dirname + '/public'),express.bodyParser());
app.listen(_listenport, _listenaddr);
app.post(_postpath, function(req, res){
  if(req.body.secretkey==_secretkey){
    delete req.body.secretkey; pub.publish(req.body.channel, JSON.stringify(req.body));
    res.send(200);
  }
});

io = socketio.listen(app);
io.configure(function () { io.set('log level', _loglevel) });

最佳答案

我刚刚找到了解决方案。

var options = {
  key: fs.readFileSync('/home/ec2-user/privatekey.pem'),
  cert: fs.readFileSync('/home/ec2-user/certificate.pem')
};


app = express.createServer(options, express.static(__dirname + '/public'),express.bodyParser());

关于node.js - 将通知系统更改为 SSL。(目前在 Chrome 中使用 https 时会被阻止,因为使用的是 http),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12924118/

相关文章:

node.js - 将 session 从 OAuth 应用程序安全地传递到浏览器

curl - SSL 证书验证失败

javascript - NodeJS SSL 验证不正确

nginx - ERR_EMPTY_RESPONSE 与 Ghost 0.7.5、Nginx 1.9、HTTPS 和 HTTP/2

node.js - 多次连接到数据库是个好习惯吗?

javascript - Moustache.js 中的列表和来自 mongodb 的 bson 数据

node.js - gcloud 部署失败并出现 "Failed to enable APIs"错误

node.js - 混淆 SSL 与 Node 和使用 cURL

c++ - Libcurl 返回损坏的数据

google-chrome - ssl 和 chrome : err_ssl_protocol_error from time to time fixed with f5