I am trying to migrate from Apache2 to NGINX and having issues with SSE connections. Everything else is working fine, the regular GET or POST requests are getting through successfully. Note that the same setup is working perfectly with Apache2 WEB server.
But there are 2 critical issues with SSE connections with NGINX server:
- The NGINX holds up responses until the buffer is full
- The NGINX blocks any other requests to the server if SSE is in progress.
With Apache2 I used to have issue #1, but it was easily resolved with the following configurations:
OutputBufferSize 0
The issue #2 is really blocking me from using NGINX. Why does the server block other connections when SSE is in progress? How to fix this issue?
The restconf application is an HTTP/REST thin client application that is called by the FastCGI module in the WEB server to start a single request session for the specified user or SSE stream.
client <-> WEB server <-> restconf <-> subsystem netconf server
I am seeing that the NGINX keeps buffering my SEE output regardless of my configuration settings. I tried to use the following:
- Setting fastcgi_buffering off in site config location ;
- Setting fastcgi_request_buffering off in site config location ;
- Setting header to X-Accel-Buffering: no in my restconf application and in the client request.
Nothing is helping. The strange part is that the buffering settings are not working at all. The size of the buffer stays the same regardless off the configurations:
- fastcgi_buffer_size 4k;
- fastcgi_buffers 4 4k;
- fastcgi_busy_buffers_size 8k;
When I change the above setting nothing is changed in the real program run. The whole event stream waits up to be sent in NGINX whether until after the application finished/terminated or the buffer is full (the size if the buffer is always the same, it's not getting changed by the above settings)
nginx -V
nginx version: nginx/1.18.0 (Ubuntu)
built with OpenSSL 1.1.1f 31 Mar 2020 (running with OpenSSL 1.1.1g 21 Apr 2020)
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-5J5hor/nginx-1.18.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC'
--prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf
--http-log-path=/var/log/nginx/access.log
--error-log-path=/var/log/nginx/error.log
--lock-path=/var/lock/nginx.lock
--pid-path=/run/nginx.pid
--modules-path=/usr/lib/nginx/modules
--http-client-body-temp-path=/var/lib/nginx/body
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-proxy-temp-path=/var/lib/nginx/proxy
--http-scgi-temp-path=/var/lib/nginx/scgi
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi
--with-debug
--with-compat
--with-pcre-jit
--with-http_ssl_module
--with-http_stub_status_module
--with-http_realip_module
--with-http_auth_request_module
--with-http_v2_module
--with-http_dav_module
--with-http_slice_module
--with-threads
--with-http_addition_module
--with-http_gunzip_module
--with-http_gzip_static_module
--with-http_image_filter_module=dynamic
--with-http_sub_module
--with-http_xslt_module=dynamic
--with-stream=dynamic
--with-stream_ssl_module
--with-mail=dynamic
--with-mail_ssl_module
The NGINX server configurations:
server {
listen 80;
listen [::]:80;
root /var/www/yang-api;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name localhost;
# need to install fcgiwrap to use RESTCONF
# set SCRIPT_FILENAME to the location of the restconf program
location /restconf {
fastcgi_param SCRIPT_NAME restconf;
fastcgi_param SCRIPT_FILENAME /var/www/yang-api/restconf;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
include /etc/nginx/fastcgi_params;
allow all;
# HAS EFFECT
## This is the maximum time limit for request handling.
## If a FastCGI request does not complete within this timeout
## seconds, it will be subject to termination.
## Set to big number if SSE used
fastcgi_read_timeout 120s;
# NO EFFECT
fastcgi_buffering off;
fastcgi_request_buffering off;
}
}