Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sithu's avatar
Level 14

File upload with nginx php5-fpm

Hello...

I've got an error every time I upload files. I've setup my server with nginx, php5-fpm, php5.6. here's the error log.

2016/03/09 14:35:23 [error] 24327#0: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 111.84.193.190, server: moda.com.mm, request: "POST /admin/magazines HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "162.243.28.246", referrer: "http://162.243.28.246/admin/magazines/create"

Any help would be very appreciate.

0 likes
10 replies
tykus's avatar

How large is the file(s)? You might have a fast-cgi timeout

willvincent's avatar

Your php config needs to be setup with large enough values for max filesize and max post body size, which I'm sure you already know..

However, you generally also need some config for nginx to allow for large-ish files.

This is the nginx upload-specific config I've used without issue for several years:

  include                   mime.types;
  default_type              application/octet-stream;
  client_max_body_size      2000M;
  client_body_buffer_size   128k;

Unless I try to exceed a 2GB upload, I have no issues regardless of file size.

Sithu's avatar
Level 14

Thanks @willvincent

I updated the setting like you said. The weird thing is my two files which are not larger than 15MB, they ware uploaded correctly. But I got 502 Bad Gateway. If I refresh, files are Okay. Do you have encounter like this?

willvincent's avatar

I've not run into that myself, no. You could try upping your keepalive time, I believe the default is 20, mine is 65:

keepalive_timeout       65;
Sithu's avatar
Level 14

it's already 65.

Unfortunately still couldn't get it to work.

fideloper's avatar

That looks like an nginx log, also check out the php-fpm log usually found in /var/log/php5-fpm.log, it may have more information. My guess is an issue in the code receiving the file, rather than the act of uploading a file itself. Usually errors due to file size are more explicit.

mdecooman's avatar

Hi @Sithu,

In addition to the client_max_body_size in nginx, did you check your php.ini settings?

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 128M


; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 128M
Sithu's avatar
Level 14

@mdecooman Thanks

I've changed these settings which is under php5-fpm. It still doesn't work.

Sithu's avatar
Level 14

Hi @fideloper Thanks big guy. I'm a big fan of serverforhackers by the way.

I also check php5-fpm log but wasn't help. For me I check almost every solution from online and configured my settings. Finally I think I over configured LEMP settings which I didn't know what to do next. So I uninstalled everything and reinstall again (followed an article from digital ocean) and it works now.

1 like

Please or to participate in this conversation.