I am running a bookstack instance in php under nginx.
Unfortunately i can't upload any file bigger than 2M. And this is my problem for today.
File upload attempt results in HTTP/1.1 422 Unprocessable Entity
with body {file: ["The file could not be uploaded. The server may not accept files of this size."]}
.
Bookstack documentation says it's enough to set up file size limits in both nginx and php (actually it also mentions some tweak in frontend, but since we have HTTP error let's leave it out of scope). No tweaks in the bookstack backend required.
php config (and there is only one version installed):
cat /etc/php/7.0/fpm/php.ini | egrep 'upload_max_filesize|post_max_size'
post_max_size = 28M
upload_max_filesize = 28M
nginx config:
cat /etc/nginx/sites-available/bookstack
server {
listen 80;
server_name ****;
return 301 https://****;
}
server {
listen 443 ssl;
server_name ****;
ssl_certificate /etc/ssl/certs/***.crt;
ssl_certificate_key /etc/ssl/private/***.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
root ***;
client_max_body_size 28m;
client_body_timeout 60;
location / {
try_files $uri /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
}
I've added this file into public
directory:
<?php
echo phpinfo();
?>
Which gives:
PHP Version 7.0.33-0ubuntu0.16.04.7
...
Server API FPM/FastCGI
...
Configuration File (php.ini) Path /etc/php/7.0/fpm
Loaded Configuration File /etc/php/7.0/fpm/php.ini
...
post_max_size 16M
upload_max_filesize 2M
So, it uses the correct php.ini
file but ignores its content?
Now, the FUN part!
I've also found that configuration is correct just after sudo service php7.0-fpm restart
:
post_max_size 28M
upload_max_filesize 28M
...but for a couple of seconds only. After one or two seconds it resets back to 2M
. And file upload actually works within these seconds (but requires a lot of dexterity...).
According to service php7.0-fpm status
output, main service process does not restart within this period, and worker process PID's remain unchanged.
Also, enabling catch_workers_output = yes
in www.conf
does not add anything useful to the fpm log.
How can i extend file upload limit for longer period than two seconds?
I guess i could just restart php-fpm every two seconds but this is not even funny, actually.
Is there more robust way to solve the problem?