我一直在使用Cloud9 IDE来进行开发,感觉非常不错。然而,我现在想要用node js建立一个简单的https服务器,但是我无法使它正常工作。当我运行页面时,Cloud9会提示“正在运行Node进程”,但是当我访问服务器应该响应的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);
谢谢你的帮助!