Search code examples
node.jsopenshiftrestify

NodeJS app on Openshift is not accessible from rhcloud.com application URL


I have deployed a working NodeJS REST service (built with Restify) that is properly started on Openshift, as I can read the log:

listening at http://127.2.188.1:8080

I have used the usual environment parameters to bind the IP and port:

vars.ipaddress = process.env.OPENSHIFT_NODEJS_IP;
vars.port = process.env.OPENSHIFT_NODEJS_PORT || '8080';

In fact, if I call my REST service while I am logged with ssh, I get the right response:

curl http://127.2.188.1:8080/something/1337

If I call the same endpoint (/something/1337) on the public URL of my application (http://myapp-myusername.rhcloud.com), I get a 503, No server is available to handle this request.

Since my application is scaled, could it be some configuration issue, and if so, how can I solve it?


Solution

  • The reason this is happening is because OpenShift uses HAProxy as a load balancer in scalable applications. HAProxy is configured to ping root '/' url for health checks to determine whether your application is up or down. In your application, you have not configured anything at the root url so when HAProxy pings '/' it gets 503, hence your application behaves like this. There are two ways you can fix this problem

    1. Create an index.html and push it to OpenShift application
    2. The better solution is to configure HAProxy configuration file. SSH into the main gear using rhc ssh --app command, then change directory to haproxy/conf, and then update option httpchk GET / to option httpchk GET /valid_location, and finally restart the HAProxy using rhc cartridge-restart --cartridge haproxy. You can check the status of your gears by going to http://myapp-myusername.rhcloud.com/haproxy-status.

    Hope this will help you.