# Nodejs express web backend behind haproxy

**URL:** <https://discourse.haproxy.org/t/nodejs-express-web-backend-behind-haproxy/5217>\
**Category:** Help!\
**Created:** [May 12, 2020, 1:40pm UTC](https://discourse.haproxy.org/t/nodejs-express-web-backend-behind-haproxy/5217 "2020-05-12T13:40:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![grvmiguel](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@grvmiguel](https://discourse.haproxy.org/u/grvmiguel)\
**Post date:** [May 12, 2020, 1:40pm UTC](https://discourse.haproxy.org/t/nodejs-express-web-backend-behind-haproxy/5217/1 "2020-05-12T13:40:46Z")

</div>

I am trying to set up a backend with nodejs and haproxy. The problem is that, when using haproxy, when you access a page, it loads, but sometimes other resources (js, css, etc) will not load (Err: Connection refused in Chrome, failed to load … in firefox)

It seems that adding `option http-server-close` in haproxy configuration file solves the problem, but why is this happening? As far as I am aware, nodejs supports keepalive and enqueues requests. What am I missing?

Thanks.

I asked this on stackoverflow [here](https://stackoverflow.com/questions/61748410/nodejs-express-web-backend-behind-haproxy).

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [May 12, 2020, 3:58pm UTC](https://discourse.haproxy.org/t/nodejs-express-web-backend-behind-haproxy/5217/2 "2020-05-12T15:58:46Z")

</div>

It’s impossibile to tell with the informations provided.

Share the entire configuration, the output of `haproxy -vv` as well as the log output of haproxy during this problem.

---

<div class="post-metadata">

**Author:** ![grvmiguel](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@grvmiguel](https://discourse.haproxy.org/u/grvmiguel)\
**Post date:** [May 13, 2020, 7:36am UTC](https://discourse.haproxy.org/t/nodejs-express-web-backend-behind-haproxy/5217/3 "2020-05-13T07:36:52Z")

</div>

Of course, sorry about that, I was on a hurry.

## Configuration file is:

global  
log /dev/log local0  
log /dev/log local1 notice  
chroot /var/lib/haproxy  
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners  
stats timeout 30s  
user haproxy  
group haproxy  
daemon

```
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private

# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
# An alternative list with additional directives can be obtained from
# https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3

```

defaults  
log global  
mode http  
option httplog  
option dontlognull  
option http-server-close # THIS LINE fixes the problem  
timeout connect 5000  
timeout client 50000  
timeout server 50000  
errorfile 400 /etc/haproxy/errors/400.http  
errorfile 403 /etc/haproxy/errors/403.http  
errorfile 408 /etc/haproxy/errors/408.http  
errorfile 500 /etc/haproxy/errors/500.http  
errorfile 502 /etc/haproxy/errors/502.http  
errorfile 503 /etc/haproxy/errors/503.http  
errorfile 504 /etc/haproxy/errors/504.http

frontend not-secure-in  
bind \*:80  
http-request redirect scheme https if { ssl\_fc,not }

frontend secure-in  
bind \*:8000 ssl crt /etc/haproxy/certs/  
use\_backend aa if { req.hdr(host) -i xxx.xxx.xxx }  
default\_backend bb

## backend bb server server\_bb localhost:9000 backend aa server server\_aa 192.168.1.201:8000

The one that gives me trouble is server\_aa, which is a full webpage. Server\_bb is a RESTAPI.  
I have commented the line that apparently solves this, but why?

* * *

$ haproxy -vv  
HA-Proxy version 1.8.8-1ubuntu0.10 2020/04/03  
Copyright 2000-2018 Willy Tarreau [willy@haproxy.org](mailto:willy@haproxy.org)

Build options :  
TARGET = linux2628  
CPU = generic  
CC = gcc  
CFLAGS = -g -O2 -fdebug-prefix-map=/build/haproxy-Lb4xC1/haproxy-1.8.8=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D\_FORTIFY\_SOURCE=2  
OPTIONS = USE\_GETADDRINFO=1 USE\_ZLIB=1 USE\_OPENSSL=1 USE\_LUA=1 USE\_SYSTEMD=1 USE\_PCRE=1 USE\_PCRE\_JIT=1 USE\_NS=1

Default settings :  
maxconn = 2000, bufsize = 16384, maxrewrite = 1024, maxpollevents = 200

Built with OpenSSL version : OpenSSL 1.1.1 11 Sep 2018  
Running on OpenSSL version : OpenSSL 1.1.1 11 Sep 2018  
OpenSSL library supports TLS extensions : yes  
OpenSSL library supports SNI : yes  
OpenSSL library supports : TLSv1.0 TLSv1.1 TLSv1.2 TLSv1.3  
Built with Lua version : Lua 5.3.3  
Built with transparent proxy support using: IP\_TRANSPARENT IPV6\_TRANSPARENT IP\_FREEBIND  
Encrypted password support via crypt(3): yes  
Built with multi-threading support.  
Built with PCRE version : 8.39 2016-06-14  
Running on PCRE version : 8.39 2016-06-14  
PCRE library supports JIT : yes  
Built with zlib version : 1.2.11  
Running on zlib version : 1.2.11  
Compression algorithms supported : identity(“identity”), deflate(“deflate”), raw-deflate(“deflate”), gzip(“gzip”)  
Built with network namespace support.

Available polling systems :  
epoll : pref=300, test result OK  
poll : pref=200, test result OK  
select : pref=150, test result OK  
Total: 3 (3 usable), will use epoll.

## Available filters : [SPOE] spoe [COMP] compression [TRACE] trace

Thanks.

---

<div class="post-metadata">

**Author:** ![grvmiguel](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@grvmiguel](https://discourse.haproxy.org/u/grvmiguel)\
**Post date:** [May 20, 2020, 10:25am UTC](https://discourse.haproxy.org/t/nodejs-express-web-backend-behind-haproxy/5217/4 "2020-05-20T10:25:56Z")

</div>

anyone?

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [July 18, 2020, 6:40pm UTC](https://discourse.haproxy.org/t/nodejs-express-web-backend-behind-haproxy/5217/5 "2020-07-18T18:40:40Z")

</div>

Most likely a buggy backend server, or, possibly a bug in haproxy.

Capture the haproxy - backend server traffic in working and non-working situation and analyze it.
