Image upload (resize) not working on nginx/php-fpm

Espen Espelund

Active member
For some reason I can't upload large images on my nginx/php-fpm setup. The problem seems related to resolution and not just filesize. A 1000x1000px 10kb image does not work. Everything works fine in WordPress with the same setup.

Did anyone experience a similar problem?

location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$uri&$args;
}

location ~ ^/(internal_data|library)/(.*)$ {
internal;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/fitnessbloggen/forum$fastcgi_script_name;
include fastcgi_params;

fastcgi_temp_file_write_size 10m;
fastcgi_busy_buffers_size 128k;
fastcgi_buffer_size 128k;
fastcgi_buffers 16 128k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}

location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
 
Did you ever figure out what the problem was? I've got basically the same issue. Upload a small-ish image, no problem. Upload a large image that needs to be resized, and it goes through the whole flash uploader to 100%, then says the upload failed.

If I switch out php-fpm for apache, it works fine. There's something in the php-fpm config that's causing the uploads to fail... they're timing out, they're bigger than the upload_max_filesize value, etc. But I'm not sure what.
 
Okay, thanks. I know that php-fpm is running as apache:apache, and I'm using nginx as the front end both ways, so user access shouldn't be an issue... oh, and I can upload anything that *doesn't* need resized, and that works fine.
 
Just a quick update. I'm not sure exactly what the cause of the problem was, but it *wasn't* a user permission issue. PHP-FPM is now running as apache:apache, and nginx runs as nginx:apache, and that works just fine. I did change php-fpm to run as nginx:apache at one point, thinking that maybe it needed to read nginx's buffer file and didn't have permission. That actually caused issues (once I got things working), because the nginx user didn't have permission to write to the data and internal-data directories. :LOL:

I think the secret sauce is in these lines. I added them to fastcgi_params:

Code:
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_max_temp_file_size 0;
 
client_body_buffer_size 10m;
client_max_body_size 16m;

I think the client_body_buffer_size and client_max_body_size were really the root of the problem. Once nginx quit buffering to disk during the uploads, I started getting usable error messages that helped highlight other problems (all minor and self-induced stuff as I was iterating through different options).

Somebody (I think Shamil?) suggested these lines:

Code:
fastcgi_pass_request_body off;
client_body_in_file_only clean;
fastcgi_param REQUEST_BODY_FILE $request_body_file;

But this didn't work for me, for whatever reason.

Anyway, I figured I'd post the details in case it helps anybody else down the line.
 
Top Bottom