[SOLVED] Openhab Cloud on AWS says "404 Not found"

  • Platform information: AWS

  • Issue of the topic:
    I was trying to setup a openhab cloud instance in a AWS (ubuntu-bionic-18.04-amd64-server) following quick start guide given here. Did required configurations to ngnix default file and config.json. However, I get 404 Not found message when trying to access this instance.
    When I try to run the app.js (sudo node app.js), I get following error:

    error: uncaughtException: Cannot find module ‘bcrypt’

Tried rebuilding package after changing the bcrypt reference to bcryptjs, but didn’t resolve the problem. Any help on this would be appreciated.

Here’s the full log when I tried to start app.js

2018-11-17T18:35:49.840Z - info: openHAB-cloud: Backend service is starting up...

2018-11-17T18:35:49.842Z - info: openHAB-cloud: Backend logging initialized…
2018-11-17T18:35:50.009Z - error: uncaughtException: Cannot find module ‘bcrypt’ date=Sat Nov 17 2018 18:35:50 GMT+0000 (UTC), pid=19582, uid=0, gid=0, cwd=/opt/openhab-cloud, execPath=/usr/bin/node, version=v8.10.0, argv=[/usr/bin/node, /opt/openhab-cloud/app.js], rss=44445696, heapTotal=19398656, heapUsed=12507320, external=18130346, loadavg=[0.00390625, 0.0673828125, 0.115234375], uptime=4122, trace=[column=15, file=module.js, function=Module._resolveFilename, line=547, method=_resolveFilename, native=false, column=25, file=module.js, function=Module._load, line=474, method=_load, native=false, column=17, file=module.js, function=Module.require, line=596, method=require, native=false, column=18, file=internal/module.js, function=require, line=11, method=null, native=false, column=14, file=/opt/openhab-cloud/models/userdevice.js, function=null, line=3, method=null, native=false, column=30, file=module.js, function=Module._compile, line=652, method=_compile, native=false, column=10, file=module.js, function=Module._extensions…js, line=663, method=.js, native=false, column=32, file=module.js, function=Module.load, line=565, method=load, native=false, column=12, file=module.js, function=tryModuleLoad, line=505, method=null, native=false, column=3, file=module.js, function=Module._load, line=497, method=_load, native=false, column=17, file=module.js, function=Module.require, line=596, method=require, native=false, column=18, file=internal/module.js, function=require, line=11, method=null, native=false, column=18, file=/opt/openhab-cloud/gcm-xmpp.js, function=null, line=8, method=null, native=false, column=30, file=module.js, function=Module._compile, line=652, method=_compile, native=false, column=10, file=module.js, function=Module._extensions…js, line=663, method=.js, native=false, column=32, file=module.js, function=Module.load, line=565, method=load, native=false], stack=[Error: Cannot find module ‘bcrypt’, at Function.Module._resolveFilename (module.js:547:15), at Function.Module._load (module.js:474:25), at Module.require (module.js:596:17), at require (internal/module.js:11:18), at Object. (/opt/openhab-cloud/models/userdevice.js:3:14), at Module._compile (module.js:652:30), at Object.Module._extensions…js (module.js:663:10), at Module.load (module.js:565:32), at tryModuleLoad (module.js:505:12), at Function.Module._load (module.js:497:3), at Module.require (module.js:596:17), at require (internal/module.js:11:18), at Object. (/opt/openhab-cloud/gcm-xmpp.js:8:18), at Module._compile (module.js:652:30), at Object.Module._extensions…js (module.js:663:10), at Module.load (module.js:565:32)]
2018-11-17T18:35:50.010Z - error: code=MODULE_NOT_FOUND

Here’s the last lines in openhab-cloud.org-error.log
2018/11/17 18:28:53 [error] 18699#18699: *1 connect() failed (111: Connection refused) while connecting to upstream, client: xx:xx:xx:xx, server: xx:xx:xx:xx
2018/11/17 18:28:53 [error] 18699#18699: *1 open() “/usr/share/nginx/html/50x.html” failed (2: No such file or directory), client: xx:xx:xx:xx, server: xx:xx:xx:xx

Any help on this is really appreciated!

I was able to fix this issue my-self.

The main issue was the nodejs version I was using. When you switch to nodejs 7, things go much smoother.

Here are the steps I followed:

  1. Created a server instance in amazon web service using ubuntu-xenial-16.04-amd64-server image
  2. Did following on using putty terminal. (You need to create a key file and convert it using puttygen in order to connect)

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential redis-server mongodb nginx python
sudo apt-get install git
cd /opt
sudo git clone GitHub - openhab/openhab-cloud: Cloud companion for openHAB instances
cd openhab-cloud
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install nodejs
npm install
cp config-development.json config.json
sudo nano config.json

  1. My config.json file looks like this
{
    "system": {
      "host": "my.domain.com",
      "port": "80",
      "protocol": "http",
      "logging": "info",
      "subDomainCookies": false,
      "muteNotifications": false
    },
    "express":{
      "key" : "some express key"
    },
    "apn" : {
      "gateway": "gateway.push.apple.com",
      "cert": "certs/aps/aps_production_cert.pem",
      "key": "certs/aps/aps_production_key.pem",
      "passphrase": "passphrase"
    },
    "gcm" : {
      "jid": "something@gcm.googleapis.com",
      "password": "password"
    },
    "ifttt" : {
      "iftttChannelKey" : "key",
      "iftttTestToken" : "token"
    },
    "mail": {
      "host" : "smtp",
      "port" : 465,
      "user" : "foo@bar.com",
      "pass" : "password"
    },
    "mongodb": {
        "hosts": ["127.0.0.1"],
        "db": "openhab"
    },
    "redis": {
        "host": "127.0.0.1",
        "port": "6379"
    },
    "mailer": {
        "host" : "smtp",
        "port": 465,
        "secureConnection": true,
        "user": "foo@bar.com",
        "password": "password",
        "from": "openHAB Cloud <your@email.address>"
    },
    "legal": {
        "terms" : "",
        "policy": ""
    },
    "registration_enabled": true
}
  1. Then I did my ngnix server related setup as below

sudo cp /opt/openhab-cloud/etc/nginx_openhabcloud.conf /etc/nginx/sites-available/default
sudo nano /etc/nginx/sites-enabled/default

This is how my ngnix setup looks like. Change MY_SERVER_NAME to your servers IP or domain name

server {
    listen 443 ssl default_server;
    ssl_certificate       /etc/letsencrypt/live/MY_SERVER_NAME/fullchain.pem;
    ssl_certificate_key   /etc/letsencrypt/live/MY_SERVER_NAME/privkey.pem;
    add_header Strict-Transport-Security "max-age=31536000";

charset utf-8;

access_log /var/log/nginx/openhab-cloud.org-access.log;
error_log /var/log/nginx/openhab-cloud.org-error.log;
client_max_body_size 300m;


location /css {
    alias  /opt/openhab-cloud/public/css;
    }
location /js {
    alias /opt/openhab-cloud/public/js;
    }
location /img {
    alias /opt/openhab-cloud/public/img;
    }
location /bootstrap {
    alias /opt/openhab-cloud/public/bootstrap;
    }
location /font-icons {
    alias /opt/openhab-cloud/public/font-icons;
    }
location /fonts {
    alias /opt/openhab-cloud/public/fonts;
    }
location /js-plugin {
    alias /opt/openhab-cloud/public/js-plugin;
    }
location /downloads {
    alias /opt/openhab-cloud/public/downloads;
    }
location / {
    proxy_pass http://localhost:3000;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header X-Real-IP $remote_addr ;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
    proxy_set_header X-Forwarded-Proto https;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
     root html;
    }
}

server {
    listen 80;
    server_name MY_SERVER_NAME;
    return 301 https://$server_name$request_uri;
}
  1. Then I tested everything to make sure they works without errors:
    sudo node app.js
    sudo service ngnix restart

You should see openhab welcome page at your servers ip if all the above has been properly setup.

  1. Making everything run at boot

sudo npm install pm2 -g
sudo pm2 start /opt/opehab-cloud/app.js
sudo pm2 save

Thant was it! Enjoy!!!

3 Likes

mark you 2nd post as the one providing the solution :slight_smile:

nice write-up btw

1 Like

Hello
Thank for your post.
Please, i have some questions.
Did you instaled SSL after created the AWS instance ?
I follow yours instructions, but some errors occured for nginx configuration.
I use AWS free server instance, and dont have a SSL installation, so when i put ssl statement in gninx configurations, like you, i get blank page in “https:MyPublicDNS”, an a error on “http:MyPublicDNS”.
But the test of gninx conf file is successful.
Thank you.

Khal, you need to setup a Lets Encrypt certificate. To do this you need to make sure your domain is valid and that LE Servers can validate it by making sure port 80 is open.

This will then install the certificates onto your server that NGINX will reference. Once you do that, you can enable the HTTPS/443 Server block and the site will be protected.

I too like anjana55 had LOADS of issues with node js. What a pile of crap that thing is seriously! anyway, its working.