9

我一直在玩 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);

谢谢您的帮助!

4

1 回答 1

0

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

它应该说,当你启动一个程序。

于 2013-11-21T23:57:02.113 回答