Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable keep-alive in node server

I am developing an application backend based on node.js server and express, the application is receiving an external flux from an apache server that require a "keep alive " disabled

So I tried to disable the option buy req.setSocketKeepAlive(false);

var http = require('http');
var express = require('express');

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
var app = express();
var server = http.createServer(app);
server.keepAliveTimeout(0)

but it doesnt work.

Do you have any ideas how to solve this issue ?

like image 728
Asmaa Djo Avatar asked Oct 06 '17 13:10

Asmaa Djo


People also ask

How do I turn off Keep-Alive?

To disable, just use “KeepAlive Off”. It sets the maximum number of requests for every Keep-Alive connection. A value of 100 is normally good enough for almost any scenario. This value, however, should be increased depending on the amount of files within a web page that the server is supposed to deliver.

Is Keep-Alive enabled by default?

Keep-Alive is enabled by default in most cases, however, sometimes hosting companies disable Keep-Alive for performance reasons. If HTTP Keep-Alive isn't enabled, you can enable it using the following options.

How do I keep a session alive in node JS?

Try something like: app. use( session( { secret: 'keyboard cat', cookie: { maxAge: 60000 }, rolling: true, resave: true, saveUninitialized: false } ) );

What is Keep-Alive enabled?

Enabling Keep-Alive ensures that a single TCP connection is used to transfer multiple files from the server to the browser. This helps your page load faster as the browser doesn't need to establish multiple connections to retrieve all your page resources.


Video Answer


1 Answers

Although not ideal, setting the Connection header to close in a middleware can help you.

Express.js close response

like image 148
Ati Ranzuglia Avatar answered Sep 27 '22 22:09

Ati Ranzuglia