简体   繁体   English

使用Node JS设置Cloud9 SSL应用程序

[英]Setting up Cloud9 SSL App with Node JS

I've been playing around with the Cloud9 IDE and am having a great time with it. 我一直在玩Cloud9 IDE并且玩得很开心。 However, I'm trying to setup a simple https server with node js and I can't seem to get it to work. 但是,我正在尝试使用节点js设置一个简单的https服务器,我似乎无法让它工作。 When I run the page, Cloud9 says 'Running Node Process' but when I visit the url that the server is supposed to respond to: https://workspace.user.c9.io the page says 当我运行页面时,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 

I created a test certificate with OPENSSL and am using the following code to set up my server. 我用OPENSSL创建了一个测试证书,并使用以下代码来设置我的服务器。 I can confirm that the OPENSSL certificate was built correctly. 我可以确认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);

Thank you for your help! 谢谢您的帮助!

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

It should say that when you start a program. 它应该说当你启动一个程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM