net::ERR_CONNECTION_CLOSED error at Chrome with HTTP2.0 + Nginx
Asked Answered
S

4

6

How to handle net::ERR_CONNECTION_CLOSED error in Google Chrome (v.51.0) when I try POST images on server (with jQuery or Dropzone.js) by https.

Firefox work great on http and https. Chrome only http. Everything without file uploading works fine on Chrome+HTTPS. I'm getting this error after php timeout ends:

dropzone.min.js:1 POST https://{example.com}/images/upload net::ERR_CONNECTION_CLOSED

No other messages. Nothing at PHP and Nginx logs.

My server: PHP 7.0.9 + Nginx 1.10 + Ubuntu Server 16.04 + HTTP2.0 with SSL cert by Comodo.

UPDATED

I found the problem and solution.

Salters answered 3/8, 2016 at 20:6 Comment(1)
Sorry but without the code is really hard to provide help....did you try with withCredentials: trueSaipan
C
2

This is a workaround, not a solution to the problem. This error was happening to me in chrome when using nginx with http2 enabled.

I was able to disable http2 in nginx (or rather simply removed the option that enabled it).

I changed:

  server {
      listen 443 http2 ssl;
      listen [::]:443 http2 ssl;

to:

  server {
      listen 443 ssl;
      listen [::]:443 ssl;

After that, chrome worked fine with nginx.

What was especially weird about my issue was that it only happened when I passed large headers, over about 500 bytes. At all other times, chrome/ngnx behaved themselves. The entire time, curl was also working fine hitting my endpoints. Additionally, chrome and all other browsers I tested worked fine when I bypassed nginx to hit the endpoints directly.

From things that I have seen, I suspect that this is an issue with ALPN. Perhaps it was because my openssl version was outdated. It was easier to downgrade to http 1.1 than to look into that possibility though.

Cardigan answered 8/9, 2018 at 2:54 Comment(3)
Having exactly the same issue here. Chrome is crapping out with large uploads when HTTP2 is enabled. Is there a "proper" solution for this?Spine
@Spine none that I know of. I looked for a long time and this was the best I could come up with or find on the internet. Looking back, since all other major browsers seem to work fine, its probably a chrome bug. So the only true solution would be to fix chrome/chromium.Cardigan
It does seem to only be relevant to Chrome and HTTP/2. I've just posted the solution that worked for me below. It's not exactly the answer for your specific situation but I found your question while I was trying to figure this out so hopefully others may find it helpful.Spine
P
1

Since it's Nginx with HTTP2, it has to be configured to allow longer headers/URLs. In my case, I need long query parameters for an web app, so I added 32k.

server {
  # ...
  http2_max_field_size 32k;
}

Worked on nginx v1.18.0 (Ubuntu).

Pfennig answered 11/5, 2023 at 19:43 Comment(0)
S
0

Not strictly an answer to this specific question but as this question came up while I was having a very similar issue I'll post it here in case it helps somebody else.

The problem I was having was pretty much the same as the OP, (any upload larger than 128mb was bombing out in Chrome) but I was using Plesk on my UB 16.04 server (nginx proxy HTTP/2) so any attempts to directly change the nginx settings were failing as Plesk overwrites them.

By default the Plesk panel applies a client_max_body_size 128m; to every nginx conf file although the default nginx setting is 1mb. This causes problems as no matter what you set with PHP nginx bombs out as soon as an upload hits anything over about 25mb. I'm not sure why that figure was important, maybe that's when nginx reads the headers for the next chunk of data? It see's that the incoming file is over 128mb and then bombs out throwing the ERR_CONNECTION_CLOSED error in Chrome. I'm not really sure, all I know is that it was a mess.

There is an option to add directives for nginx in Plesk that is supposed to allow you to override this but it throws "duplicate entry" errors if you try to add anything :

Invalid nginx configuration: nginx: [emerg] "client_max_body_size" directive is duplicate in /var/www/vhosts/system/example.com/conf/vhost_nginx.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed

I spent ages trying to find a fix and then found this article on Plesk's support forum which actually does the job.

Just a few simple steps (all detailed in the article) via the terminal to get it working, but just in case that ever vanishes into the ether...

Connect to the server with ssh.

Run the following command in order to add 'client_max_body_size 128m;' to the configuration of nginx:

echo 'client_max_body_size 128m;' > /etc/nginx/conf.d/aa_client_max_body.conf

As a result, 128m will be the default value of 'client_max_body_size' directive server-wide. Any other value can be set here.

Add the following lines to the /usr/local/psa/admin/conf/panel.ini:

[webserver]
nginxClientMaxBodySize = 

If the panel.ini file does not exist, create it using sample file:

cp /usr/local/psa/admin/conf/panel.ini.sample /usr/local/psa/admin/conf/panel.ini

Make sure that permissions of the file /usr/local/psa/admin/conf/panel.ini are correct, otherwise the workaround will not work:

ls -la /usr/local/psa/admin/conf/panel.ini
-rw-r--r-- 1 root root 1857 Nov 26 11:03 /usr/local/psa/admin/conf/panel.ini

Regenerate NGINX\Apache configuration files for all vhosts to apply changes in /usr/local/psa/admin/conf/panel.ini:

plesk sbin httpdmng --reconfigure-all

As a result, there will not be 'client_max_body_size' directive defined in vhosts' configuration files.

Restart NGINX:

service nginx restart

Now it is possible to specify custom value of client_max_body_size in Domains > example.com > Apache & Nginx settings > Additional nginx directives per domain, i.e:

client_max_body_size 512m;

This works 100%. Full credit to Bulat Tsydenov (the author of this solution).

Saved my bacon :)

Spine answered 6/1, 2019 at 2:38 Comment(0)
A
0

My solution work based on Kubernetes and use nginx-ingress, and connections beetween Angular SPA application and .NET API have the same error net::ERR_CONNECTION_CLOSED

For me problem was solved when I increased the parameter in global nginx

ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
 name: nginx-ingress-controller
data:
 keep-alive-requests: '1000'

The number of requests that can be processed by a persistent connection between Nginx and the client, which defaults to 100. Is recommend that you increase this number in high-concurrency scenarios. References: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#keep-alive-requests

Accept answered 22/4 at 21:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.