部署在CloudFoundry上的nodejs如何正确使用port环境变量

227 阅读1分钟

做一个试验:

scp上运行一个nodejs服务器,监听在8080端口上:

clipboard1

能够工作:

clipboard2

改成另一个端口8081:

clipboard3

clipboard4

就不行了:

clipboard5

TIP: Application must be listening on the right port. Instead of hard coding the p ont, use the $PORT environment variable
Use ‘cf logs jerry-demo-server --recent’ for more informatior FAILED

原因是因为SAP云平台 CloudFoundry环境下的应用默认监听在端口8080上:

By default, apps only receive requests on port 8080 for both HTTP and TCP routing, and so must be configured, or hard coded, to listen on this port. Configuring custom app ports allows developers to bring workloads onto Cloud Foundry that listen on ports other than 8080.

如果想监听在其他端口,请参考CloudFoundry官方文档:

docs.cloudfoundry.org/devguide/cu…

要获取更多Jerry的原创文章,请关注公众号"汪子熙":