1

I am trying to deploy an AdonisJS app on Elastic Beanstalk. I have followed several tutorials to do so but I am getting 502 Bad Gateway :(

I have set PORT env variable to 8081 from the Configuration portal as suggested in all the tutorials out there.

----------------------------------------
/var/log/nginx/error.log
----------------------------------------
2020/12/28 19:54:52 [error] 5218#0: *266 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.xxx.xx, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "172.xx.xx.x"
----------------------------------------
/var/log/web.stdout.log
----------------------------------------
Dec 28 20:06:36 ip-xxx-31-30-5 web: > adonis-api-app@4.1.0 start /var/app/current
Dec 28 20:06:36 ip-xxx-31-30-5 web: > node server.js
Dec 28 20:06:37 ip-xxx-31-30-5 web: #033[32minfo#033[39m: serving app on http://xxxxx-api-staging.us-west-2.elasticbeanstalk.com:8081
Dec 28 20:06:37 ip-xxx-31-30-5 web: events.js:291
Dec 28 20:06:37 ip-xxx-31-30-5 web: throw er; // Unhandled 'error' event
Dec 28 20:06:37 ip-xxx-31-30-5 web: ^
Dec 28 20:06:37 ip-xxx-31-30-5 web: Error: listen EADDRNOTAVAIL: address not available 44.242.xx.xx:8081
Dec 28 20:06:37 ip-xxx-31-30-5 web: at Server.setupListenHandle [as _listen2] (net.js:1300:21)
Dec 28 20:06:37 ip-xxx-31-30-5 web: at listenInCluster (net.js:1365:12)
Dec 28 20:06:37 ip-xxx-31-30-5 web: at GetAddrInfoReqWrap.doListen [as callback] (net.js:1502:7)
Dec 28 20:06:37 ip-xxx-31-30-5 web: at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:68:8)
Dec 28 20:06:37 ip-xxx-31-30-5 web: Emitted 'error' event on Server instance at:
Dec 28 20:06:37 ip-xxx-31-30-5 web: at emitErrorNT (net.js:1344:8)
Dec 28 20:06:37 ip-xxx-31-30-5 web: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
Dec 28 20:06:37 ip-xxx-31-30-5 web: code: 'EADDRNOTAVAIL',
Dec 28 20:06:37 ip-xxx-31-30-5 web: errno: 'EADDRNOTAVAIL',
Dec 28 20:06:37 ip-xxx-31-30-5 web: syscall: 'listen',
Dec 28 20:06:37 ip-xxx-31-30-5 web: address: '44.242.xx.xx',
Dec 28 20:06:37 ip-xxx-31-30-5 web: port: 8081
Dec 28 20:06:37 ip-xxx-31-30-5 web: }
Dec 28 20:06:37 ip-xxx-31-30-5 web: npm ERR! code ELIFECYCLE
Dec 28 20:06:37 ip-xxx-31-30-5 web: npm ERR! errno 1
Dec 28 20:06:37 ip-xxx-31-30-5 web: npm ERR! adonis-api-app@4.1.0 start: `node server.js`
Dec 28 20:06:37 ip-xxx-31-30-5 web: npm ERR! Exit status 1
Dec 28 20:06:37 ip-xxx-31-30-5 web: npm ERR!
Dec 28 20:06:37 ip-xxx-31-30-5 web: npm ERR! Failed at the adonis-api-app@4.1.0 start script.
Dec 28 20:06:37 ip-xxx-31-30-5 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Dec 28 20:06:37 ip-xxx-31-30-5 web: npm ERR! A complete log of this run can be found in:
Dec 28 20:06:37 ip-xxx-31-30-5 web: npm ERR!     /home/webapp/.npm/_logs/2020-12-28T20_06_37_082Z-debug.log

Please help as its getting really frustrating now :(

Thank you

  • 1
    Is your `HOST` variable set to `0.0.0.0`? – crbast Dec 28 '20 at 21:34
  • @crbast no. Should I set it to 0.0.0.0? – Muzammil Versiani Dec 29 '20 at 12:32
  • @crbast can you also tell me how can I execute `node ace migration:run` on the environment. I have a script under .ebextensions folder but the deployment is failed when I use the script. Without script everything is fine but database doesn't work since there is no table. Thanks! – Muzammil Versiani Dec 29 '20 at 12:50
  • I'm glad it works :) For your second question, please open a new question with logs details (I would be happy to answer). Thank you – crbast Dec 29 '20 at 13:05

1 Answers1

1

Use 0.0.0.0 as HOST variable.

The error occured because the application is not accessible. Set HOST=0.0.0.0 to make the server listen on all interfaces.

You can see more details about 0.0.0.0 here : What is the difference between 0.0.0.0, 127.0.0.1 and localhost?

crbast
  • 2,192
  • 1
  • 11
  • 21
  • I am moving to EC2, Elastic beanstalk has a lot of issues, once I get the deployment error, it never gets fixed even if I restore the old working version of the app. – Muzammil Versiani Dec 29 '20 at 13:17
  • I'm don't know EC2 but try delete full application and retry full deployment – crbast Dec 29 '20 at 15:12