Nodejs openshift app deployed code not working

时光毁灭记忆、已成空白 提交于 2019-12-23 05:47:23

问题


I am working on nodejs app,i wrote server listening code,then i deployed code into openshift hosting,there i am getting 503 response,in local if i run this code it is properly working.

code:

var http = require('http');
var express = require('express');
var fs      = require('fs');


var app = express();
app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 8080);
app.set('ip', process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1');

http.createServer(app).listen(app.get('port'), app.get('ip'), function(){
    console.log('Express server listening on port ' + app.get('port'));
});

app.get('/', function (req, res) {
    res.send('Hello World!');
});

回答1:


Do you pass the OPENSHIFT_NODEJS_IP variable? Quite often the problem is that the nodejs application is listening on IP 127.0.0.1 like in this case, but should on 0.0.0.0. If that doesn't help please provide more details on how you created the application in OpenShift.




回答2:


Here are a few tricks that might help determine what the issue is. The first way I approach it is to ssh into the OpenShift cartridge. Assuming the name of your application is hello_world:

rhc ssh -a hello_world

Once inside, type:

lsof -i | grep node

This should list out the running node processes along with the ips and ports that each is listening to. I have two node applications running, so my output looks like this:

node    23028     3389   11u  IPv4 518408054      0t0  TCP 127.6.158.129:8097 (LISTEN)
node    23028     3389   12u  IPv4 518408056      0t0  TCP 127.6.158.129:8080 (LISTEN)

So my node applications are listening on an actual ip address other than localhost. My guess is that you will see something to this effect:

node    23028     3389   11u  IPv4 518408054      0t0  TCP 127.0.0.1:8080 (LISTEN)

Next, check your environment:

env | grep OPENSHIFT_NODEJS

Mine looks like this:

OPENSHIFT_NODEJS_PORT=8080
OPENSHIFT_NODEJS_IP=127.6.158.129

So I can see that the OPENSHIFT_NODEJS_PORT and OPENSHIFT_NODEJS_IP matches the output of my lsof statement above, so I'm all good.

I'm sure you will see a discrepancy after doing all this, and that will be your clue.



来源:https://stackoverflow.com/questions/41966124/nodejs-openshift-app-deployed-code-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!