504 Gateway Timeout error with NuxtJS application running on Nginx - node.js

I have a Nuxt JS SSR site hosted on digital ocean. I am using nginx as reverse proxy with configuration as described at Nuxtjs website. I also use pm2 to run nuxt app. Everything works fine until I gat 504 and 502 errors. When I check ngnix logs it shows erros like this:
"[error] 2767773#2767773: *1655282 upstream timed out (110: Connection
timed out) while reading response header from upstream, client:
x.x.x.x, server: leadersport.ge, request: "GET /news/devils HTTP/1.1",
upstream: "http://x.x.x.x:8000/xxxx/xxxx", host: "xxx.com"
It seems like there is problem with Nuxtjs app. I inspected my Nuxtjs application(I use pm2 monit, and also I log every error inside my nuxtjs app) but it seems to work fine. After 504 error I check nuxtjs logs and there seems to be no problem. Could it be that I miss something regarding nuxtjs app? If so how could I find out what is exactly the problem with nuxtjs app? Or could it be the problem with nginx configuration?
I also check memory and cpu usage and it seems to be okay.

Related

502 Bad Gateway nginx/1.10.3 (Ubuntu) - Angular app down

I have an website in Angular hosted on AWS. On my local machine, the app works with npm start. However, when I ssh and update the changes I get an 502 Bad Request Error. It looks like this might be a dependency issue. Do you know know to troubleshoot this?

Google app engine error the server encountered a temporary error and could not complete your request

I am using Google app engine and previously everything was working fine but now when I am trying to deploy my app then i am facing this error.
Then i tried to see in my logs and in logs i found the error logs were
[error] 32#32: *2211 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 130.211.0.251, server: , request: "GET /_ah/health HTTP/1.1", upstream: "http://172.17.0.1:8080/_ah/health", host: "10.142.0.4"
Why am I getting this error? Previously everything was working fine and I haven't changed anything in my code.
I have also seen this SO post /appengine-nodejs-random-the-server-encountered-a-temporary-error-and-could-not but i cannot delete all versions of my app engine and try again.
I don't know why but problem was occuring because i was running my nodejs app on Port 3000, but as i changed it to 8080 now it is working fine. I think default port google cloud uses is 8080 maybe.

Angular 2 Routing with Amazon EC2 404 error

I am trying to get a deployment of a MEAN stack app using angular2 v1.0.0 beta.3 up and running. Everything is going well so far except this annoying routing issue that did NOT occur when I deployed to Heroku. However; this is my first experience deploying to ec2 using elastic beanstalk.
When I open up the route at the base route / the page loads as normal and I can use the app as if nothing is wrong. However, if I navigate to a subroute, in my case /client/issue/:id , the state loads, but if I reload the page I will get a 404 ERROR. In my server.js I have what I thought was a 404 catch app.get('*', loadIndex'), but this does not seem to be the case. I assume it is an issue with the way ec2 handles routing, but I am not sure.
EDIT
It might also be worth noting that I am only getting an error in my /var/log/nginx/error.log file and not the /var/log/nodejs/nodejs.log file.
From the error.log file:
2016/04/06 15:14:00 [error] 18952#0: *16 open() "/var/app/current/client/Issue/yes/57044092fe1924e77d9049ab" failed (2: No such file or directory), client: 172.31.4.202, server: , request: "GET /client/Issue/yes/57044092fe1924e77d9049ab HTTP/1.1",

Deploying on beanstalk with express 4 build

I followed the instructions here http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs_express.html and it works fine if I use the aws examples.
But when I tried it by myself, the basic Express skeleton, expected to give an output of "Express \n Welcome to Express", isn't working and is giving a 502 Bad Gateway error.
I noticed that my build is with Express 4.2 whereas the aws examples use Express 3.x.
From the beanstalk logs:
2014/06/28 03:41:57 [error] 1930#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: xxx.xx.xxx.xx, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "my-env-xxxxxxxxxn.elasticbeanstalk.com"
There is no database, and no code changed from the skeleton generated by express.
(And btw, it works just fine if I do a npm start locally on my mac)
Please help.
Update: The solution mentioned in the link below answer works in this case.
502 Bad Gateway Deploying Express Generator Template on Elastic Beanstalk
Though it is not clear to me exactly why AWS would execute in that order.

502 Gateway Error on AWS - API

I am creating a test web app and have deployed it to AWS Ubuntu server using nginx..
I am getting a 502 Bad Gateway error when it tries to reach my API..
I am new to this and have started node.js and all seems to working fine except when I want to perform an API call to mongodb to read or write information. it is working fine locally so I am at a loss....
GET http://ec2-54-72-145-112.eu-west-1.compute.amazonaws.com/api/rest/golf 502 (Bad Gateway)
this is nginx server config
location /xxxxxxxxxxxxxxx{
alias /home/ubuntu/xxxxxxxxxxxxxx/site/public;
}
location /api/ {
proxy_pass http://127.0.x.1:8180/api/;
}
..
I know I may not be giving enough info but hopefully someone has an idea..
Thanks!
The nginx error message HTTP 502 indicates the nginx is working fine but cannot reach your specified proxy. So I'd suggest you to check whether the port and binding IP are correct.
You can check which ports are bound by which application using this command on your Ubuntu machine:
netstat -tulpen
You should see a line with the column "Local Address" and in your case the value 127.0.x.1:8180. If it's not there try to figure out which port is bound by your node application and reconfigure the nginx to use that port.

Resources