nginx node upstream prematurely closed connection while reading response header - node.js

I have a nodejs server running behind nginx on elastic beanstalk. I think the following error is because of a promise that isn't being activated?
Does anyone have a better idea about what it is?
2017/03/20 12:18:02 [error] 3503#0: *7363 upstream prematurely closed
connection while reading response header from upstream, client: 111.11.11.111,
server: , request: "POST /api/v1/some/url HTTP/1.1", upstream:
"http://127.0.0.1:8081/api/v1/some/url", host: "some.website.com"

we are also looking to solve that issue. From what I found, it looks like it is because your nodejs does not give a response fast enough. Hope it helps...

Related

Nodejs connect() failed (111: Connection refused) while connecting to upstream, client: localhost, server: , request: "GET / HTTP/1.1", upstream

I deloyed my Nodejs app to beanstalk service, I am able to Signup and Login my app, but after i Login, it just keeps buffering, not pulling any data, i checked my AWS logs and found this error
2021/10/22 23:43:09 [error] 3610#3610: *1 connect() failed (111: Connection refused) while connecting to upstream, client: ip-address, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "ip-address"
i have changed my settings on my security groups in configuration with no luck, would be glad to get some assistance here. Thank you!

sockjs-node net::ERR_CONNECTION_REFUSED [duplicate]

This question already has an answer here:
GET: ERR_SSL_PROTOCOL_ERROR nginx + vue.js
(1 answer)
Closed 3 years ago.
I created a brand new tiny webapp with vue cli, so without adding anything, apart from what the empty vue-cli scaffolding brings:
(base) marco#pc:~/vueMatters/testproject$ npm run serve
> testproject#0.1.0 serve /home/marco/vueMatters/testproject
> vue-cli-service serve
INFO Starting development server...
98% after emitting CopyPlugin
DONE Compiled successfully in 1409ms 8:14:46 PM
App running at:
- Local: localhost:8080
- Network: 192.168.1.7:8080
Note that the development build is not optimized.
To create a production build, run npm run build.
And got this error message :
GET https://localhost/sockjs-node/info?t=1580228998416 net::ERR_CONNECTION_REFUSED
node --version
v12.10.0
npm -v
6.13.6
webpack-cli#3.3.10
Ubuntu 18.04.03 Server Edition
last lines of /var/log/nginx/error.log :
2020/01/28 18:10:57 [error] 980#980: *34 connect() failed (111:
Connection refused) while connecting to upstream, client:
66.249.79.119, server: ggc.world, request: "GET /robots.txt HTTP/1.1",
upstream: "http://127.0.0.1:8080/robots.txt", host: "ggc.world"
2020/01/28 18:11:37 [error] 980#980: *36 connect() failed (111:
Connection refused) while connecting to upstream, client: 66.249.79.70,
server: ggc.world, request: "GET /robots.txt HTTP/1.1", upstream:
"http://127.0.0.1:8080/robots.txt", host: "www.ggc.world"
How to solve the problem?
You need to specify SSL Certificates in your socket connections.
Here is the reference.
var options = {
key: fs.readFileSync('./file.pem'),
cert: fs.readFileSync('./file.crt')
};
var server = https.createServer(options, app);
var io = require('socket.io')(server);

AWS elastic Beanstalk / nginx : connect() failed (111: Connection refused

I got this message
connect() failed (111: Connection refused
Here is my log:
-------------------------------------
/var/log/nginx/error.log
-------------------------------------
2018/10/21 06:16:33 [error] 4282#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.4.119, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "hackingdeal-env.qnyexn72ga.ap-northeast-2.elasticbeanstalk.com"
2018/10/21 06:16:33 [error] 4282#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.4.119, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8081/favicon.ico", host: "hackingdeal-env.qnyexn72ga.ap-northeast-2.elasticbeanstalk.com", referrer: "http://hackingdeal-env.qnyexn72ga.ap-northeast-2.elasticbeanstalk.com/"
I am using nodejs/express Elastic Beanstalk env.
I have one nginx related file in
.ebextensions/nginx/conf.d/proxy.conf
Upper file contains:
client_max_body_size 50M;
Whenever I try to get my webpage I got 502 bad gateway.
What's wrong with my app?
Just recording my incident here just in case it helps someone or my future self. I had a Django application that had SECURE_SSL_REDIRECT set to True. Since I had no load balancers configured to handle HTTPS traffic I was getting a timeout. Setting it to False fixed the issue. Couple of days wasted on that one.
111 connection refused likely means your app isn't running on the server/port combination. Also check that the security group for your app instance (or load balancer) has an inbound rule set to allow traffic from the nginx instance
I was dealing with this error on my NodeJS application (NEXTJS). Posting this here just in case is useful for someone.
My error was thet the deploy command failed at the build step (next build), which means the Node server never restarted. For that reason nginx could not find the server. You can find this kind of errors in the web.stdout.log
I tested my build command locally, fixed the errors and it worked!

Remove request from nginx error logs

How can we remove request url being logged in nginx error logs. For example it looks something like:
2015/09/01 15:26:03 [error] 30547#0: *208725 upstream prematurely closed connection while reading response header from upstream, client: 123.123.50.44, server: test.example.com, request: "GET /v1.3/status.json?...."
is it possible to drop request since it can have PII from the log(if present) so it looks something like:
2015/09/01 15:26:03 [error] 30547#0: *208725 upstream prematurely closed connection while reading response header from upstream, client: 123.123.50.44, server: test.example.com
I was able to configure access logs but couldn't find a way to customize error logs.
Edit:
Is there a way to stop logging only upstream errors?

node.js on elastic beanstalk: firefox 502 bad gateway

I'm running node on aws elastic beanstalk and everything was fine until I started getting a "502 Bad Gateway" when running an ajax request in a browser.
Checking the logs I see:
2014/12/09 18:56:48 [error] 25746#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 108.56.255.64, server: , request: "OPTIONS /match/update HTTP/1.1", upstream: "http://xxxx:8081/match/update", host: "xxxx.elasticbeanstalk.com"
2014/12/09 18:56:50 [error] 25746#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 108.56.255.64, server: , request: "POST /match/update HTTP/1.1", upstream: "http://xxxx:8081/match/update", host: "xxxx.elasticbeanstalk.com"
I've implemented CORS in node.js so cross domain requests should be ok:
app.all('/', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
Any ideas?
I found my problem. I had a document.write line in the jQuery portion of the web page making the ajax call. This didn't cause a problem when running locally, but when running on elastic beanstalk, there were two calls made (one for OPTIONS and the other the POST), the first ajax call OPTIONS runs ok, but the document.write would interrupt the POST, terminating the connection. I spent the entire day on this and my problem was a simple document.write. So make sure your async processes can run to completion when loading your page.

Resources