使用Express的Nodejitsu上的HTTPS

好的。 我有一个应用程序快速也使用Socket.io,并通过HTTP工作正常。 但是,现在我必须转移到HTTPS。 Nodejitsu提供了很多这方面的文档。 他们build议使用node-http-proxy( https://github.com/nodejitsu/node-http-proxy )。 精细!

从HTTP的代码:

var server = http.createServer(app) // app is an Express instance server.listen(config.port,config.hostip) // config.port is 80 for localhost and 3000 for Nodejitsu, config.hostip is 127.0.0.1 for localhost and 0.0.0.0 for Nodejitsu 

我懂了:

 var server = http.createServer(app) var options = { https: { key: fs.readFileSync(__dirname+"/ssl/privatekey.pem", 'utf8'), cert: fs.readFileSync(__dirname+"/ssl/certificate.pem", 'utf8') } } httpProxy.createServer(config.port, config.hostip, options).listen(3001,config.hostip) var proxy = new httpProxy.HttpProxy({ target: { host: config.hostip, port: config.port } }) https.createServer(options.https, function (req, res) { proxy.proxyRequest(req, res) }).listen(3002,config.hostip) server.listen(config.port,config.hostip) 

当我最后部署(部署期间没有错误),我访问页面,看到502错误套接字挂断。 好吧,我可能做错了,所以我只是从https://github.com/nodejitsu/node-http-proxy “从HTTPS代理到HTTP”复制并粘贴示例来检查它是否工作。 但它不 – 502错误。

它在我的本地主机上正常工作。 我也尝试启动独立HTTPS服务器没有节点HTTPS代理,但没有运气。 请帮忙,我连这个星期都解决不了。

自己find的。 Nodejitsu默认提供SSL,只需通过HTTPS://访问您的网站。 要让自定义域名申请SSL证书,您需要订阅商业计划书。