简体   繁体   English

在OpenShift node.js服务器上部署存储库

[英]Deploying a repository on an OpenShift node.js server

I'm using the Wercker Continuous Integration & Delivery Platform to test and deploy a BitBucket repository on a node.js OpenShift server. 我正在使用Wercker持续集成和交付平台在node.js OpenShift服务器上测试和部署BitBucket存储库。 Wercker loads in the BitBucket repository, builds it, tests it in the node.js environment, and passes it without any issue. Wercker将其加载到BitBucket存储库中,对其进行构建,然后在node.js环境中对其进行测试,然后将其顺利通过。 It's also checking the code with jsHint, and returns without any errors. 它还使用jsHint检查代码,并且返回没有任何错误。

Wercker also indicates that the deployment passes without errors, as does OpenShift. Wercker和OpenShift一样也表明部署顺利通过。 The problem is that when I check the application URL provided to me by OpenShift, it results with a server error: 问题是,当我检查OpenShift提供给我的应用程序URL时,会导致服务器错误:

503 Service Temporarily Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

In troubleshooting this, I restarted the server (I'm running the basic account, and I have that option) but that doesn't seem to resolve the issue. 在对此进行故障排除时,我重新启动了服务器(我正在运行基本帐户,并且具有该选项),但这似乎无法解决问题。 Neither Wercker or Openshift indicate that there is a problem, but for some reason, I'm simply unable to access that domain without error. 无论是Wercker还是Openshift都不表明存在问题,但是由于某种原因,我根本无法毫无错误地访问该域。

How can I fix this (with the most basic tier)? 如何解决此问题(使用最基本的层)?

This was the solution: 这是解决方案:

I installed the RHC client tools available on the OpenShift website, checked the application logs, and found that OpenShift was unable to find a server.js file in the root directory. 我安装了OpenShift网站上可用的RHC客户端工具,检查了应用程序日志,发现OpenShift无法在根目录中找到server.js文件。 So I renamed my app.js file to server.js, and in my package.json I changed the "start" value to server.js. 因此,我将app.js文件重命名为server.js,并在package.json中将“开始”值更改为server.js。 Then I configured the code in server.js file to the OpenShift environment variables, and that did it! 然后,我将server.js文件中的代码配置为OpenShift环境变量,然后就完成了!

The server.js now reads: 现在,server.js读取:

var http = require('http');
var ip = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1',
    port = process.env.OPENSHIFT_NODEJS_PORT || '8080';

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(port, ip);
console.log('Server running at http://'+ip+':'+port+'/');

I'm now able to connect to the application URL and get the basic "Hello World" response. 现在,我可以连接到应用程序URL并获得基本的“ Hello World”响应。

(If at this point you're still unable to connect to your application, restart your server, and that should do the trick.) (如果此时您仍然无法连接到应用程序,请重新启动服务器,这应该可以解决问题。)

I hope this helps someone else in the future. 我希望这对以后的人有所帮助。

Here's a helpful resource that I leaned on: https://gist.github.com/ryanj/5267357 这是我所依赖的有用资源: https : //gist.github.com/ryanj/5267357

Your app should be able to listen to the IP and port defined by Openshift's reverse proxy. 您的应用程序应该能够监听Openshift的反向代理定义的IP和端口。

You need to change the port number and perhaps the IP in the server configuration. 您需要在服务器配置中更改端口号或IP。

Explained here: OpenShift node.js Error: listen EACCES 在这里解释: OpenShift node.js错误:收听EACCES

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

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