Openshift node.js 部署成功,但“应用程序不可用" [英] Openshift node.js successful deployment, but "Application is not available"

查看:95
本文介绍了Openshift node.js 部署成功,但“应用程序不可用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在让 node.js 应用程序在 Openshift 上运行时遇到问题.

I'm having a problem getting a node.js app to run on Openshift.

我已将我的 openshift 项目设置为从 git 存储库中提取.

I've set up my openshift project to pull from a git repo.

我的 server.listen 调用是这样进行的:

My server.listen call is being made like this:

var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || 8080;
var ip = process.env.OPENSHIFT_NODEJS_IP || process.env.IP || '127.0.0.1';

var server = http.createServer(myServerFunction);
server.listen(port, ip);

拉取和构建工作正常.我可以在 pod 终端中看到我的应用程序正在运行,因为有一些 console.log 输出表明了这一点.我还可以看到 process.env.OPENSHIFT_NODEJS_IPprocess.env.IP 都不存在,因此端口默认为 8080.

The pull and build work fine. I can see in the pod terminal that my app is running because there is some console.log output indicating this. I can also see that neither process.env.OPENSHIFT_NODEJS_IP nor process.env.IP exist, and so the port has defaulted to 8080.

如果我进入 pod 的终端并执行 curl http://localhost:8080,我会准确地看到我期望从我的应用程序中得到的 html 输出.

If I go into the pod's terminal and execute curl http://localhost:8080 I see precisely the html output I would expect from my app.

但是,当我单击概览选项卡并找到我的应用程序的外部 url(格式为 http://<application>-<domain>.1d35.starter-us-east-1.openshiftapps.com),单击该链接会导致 openshift 的应用程序不可用"错误页面.

However, when I click on the overview tab and find the external url for my app (which is of the format http://<application>-<domain>.1d35.starter-us-east-1.openshiftapps.com), clicking that link results in openshift's "Application is not available" error page.

在我看来,我的节点应用程序运行良好,但未连接到外部 url.我怀疑 8080 不是正确的端口,我需要做更多配置才能让我的 nodejs 应用程序在 process.env.OPENSHIFT_NODEJS_PORT 接收值.

It seems to me that my node app is running perfectly well, but is not connected to the external url. I suspect that 8080 is not the correct port, and that I am required to do more configuration in order for my nodejs app to receive a value at process.env.OPENSHIFT_NODEJS_PORT.

在其他 stackoverflow 答案中,当 process.env.OPENSHIFT_NODEJS_IP 未设置时,我还看到 0.0.0.0 作为默认值.这会有所作为吗?

In other stackoverflow answers I've also seen 0.0.0.0 as the default when process.env.OPENSHIFT_NODEJS_IP is not set. Could this make a difference?

总的来说,如何将外部 url 链接到我的 nodejs 服务器?

感谢您的帮助!

推荐答案

转到
应用程序服务,
点击您的服务,
单击操作 >编辑 YAML,
在端口部分,
将 port 和 targetPort 更改为运行 nodejs 应用程序的端口,
就我而言,它在端口 8000 上,
所以我是这样给的

go to
Applications > Services,
click on your service,
click Actions > Edit YAML,
In ports sections,
change port and targetPort to the port that your nodejs application is running on,
in my case it was on port 8000,
so i gave like this

port: 8000
protocol: TCP
targetPort: 8000

另外,检查应用程序是否在0.0.0.0"而不是127.0.0.1"上运行

Also, check that app is running on "0.0.0.0", not "127.0.0.1"

这篇关于Openshift node.js 部署成功,但“应用程序不可用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆