【问题标题】:Setting up Cloud9 SSL App with Node JS使用 Node JS 设置 Cloud9 SSL 应用程序
【发布时间】:2013-04-06 08:16:50
【问题描述】:

我一直在使用 Cloud9 IDE,并且玩得很开心。但是,我正在尝试使用节点 js 设置一个简单的 https 服务器,但我似乎无法让它工作。当我运行页面时,Cloud9 说“正在运行节点进程”,但是当我访问服务器应该响应的 url 时:https://workspace.user.c9.io 页面显示

Service Temporarily Unavailable

The server you are trying to contact is down either because it was stopped or is unable to service your request due to maintenance downtime or capacity problems. Please try again later.
node-web-proxy/0.4 Server at project-livec9f70a01ca28.rhcloud.com Port 8000 

我使用 OPENSSL 创建了一个测试证书,并使用以下代码设置我的服务器。我可以确认 OPENSSL 证书构建正确。

var https = require("https");
var fs = require("fs");
var url = require("url");

var options = {
    key: fs.readFileSync('certs/cert.pem'),
    cert: fs.readFileSync('certs/cert.pem')
};


// create a server

https.createServer(options, function(req, res) {

    console.log("This works!");

    res.writeHead(200);
    res.end("Hello world from Cloud9! Url:"+req.url);

}).listen(process.env.PORT);

感谢您的帮助!

【问题讨论】:

  • 你能让http服务器工作吗?

标签: node.js ssl https configuration


【解决方案1】:

你需要.listen(process.env.PORT,process.env.IP);

当你启动一个程序时应该这样说。

【讨论】:

    猜你喜欢
    • 2019-04-04
    • 2011-06-19
    • 1970-01-01
    • 2017-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 2016-04-12
    相关资源
    最近更新 更多