by dofrance | May 16, 2014 | Daily Sysadmin, Information Technology
If Nginx aborts your connection when uploading large files, you will see something like below in Nginx’s error logs:
[error] 25556#0: *52 client intended to send too large body:
This means, you need to increase PHP file-upload size limit. Following steps given below will help you troubleshoot this!
Changes in php.ini
To change max file upload size to 100MB
Edit…
vim /etc/php5/fpm/php.ini
Set…
upload_max_filesize = 100M
post_max_size = 100M
Notes:
- Technically, post_max_size should always be larger than upload_max_filesize but for large numbers like 100M you can safely make them equal.
- There is another variable max_input_time which can limit upload size but I have never seen it creating any issue. If your application supports uploads of file-size in GBs, you may need to adjust it accordingly. I am using PHP-FPM behind Nginx from very long time and I think in such kind of setup, its Nginx to which a client uploads file and then Nginx copies it to PHP. As Nginx to PHP copying will be local operation max_input_time may never create issue. I also believe Nginx may not copy the file but merely hand-over the location of file or descriptor records to PHP!
You may like to read
these posts which explains PHP file upload related config in some details.
Change in Nginx config
Add following line to http{..} block in nginx config:
http {
#...
client_max_body_size 100m;
#...
}
Note: For very large files, you may need to change value of client_body_timeout parameter. Default is 60s.
Reload PHP-FPM & Nginx
service php5-fpm reload
service nginx reload
Changes in WordPress-Multisite
Go to: Network Admin Dashboard >> Settings. Look for Upload Settings
Also change value for Max upload file size
https://rtcamp.com/tutorials/php/increase-file-upload-size-limit/
by dofrance | Apr 25, 2014 | Daily Sysadmin, Information Technology
First Production Ubuntu Server 14.04 running:
- MariaDB (Mysql)
- Nginx
- Php5-fpm
- Zabbix 2.2.*
All Stock Packages no Extra Repositories is needed. It Awesome!
DIY Ubuntu Server 14.04, it extremely easy. I mount /var on seperate hard disk for Mysql perfomance. MariaDB have many advantage than Mysql (belong to Oracle already).
hostname zabbix.mydomain.vn && echo ‘zabbix.mydomain.vn ‘ > /etc/hostname
Note:
- datetime: sync your server to your NTP server.
- Notice your mysql password
sudo apt-get update && apt-get -y dist-upgrade
sudo apt-get install mariadb-server nginx php5-fpm php5-mysql snmp libnet-snmp-perl snmp-mibs-downloader
sudo apt-get install zabbix-server-mysql zabbix-frontend-php zabbix-agent
MariaDB Mysql
create zabbix user, zabbix database, grant privileges for zabbix user on database zabbix.
mysql -u root -p
Enter password: your root password at MariaDB installation
create user ‘zabbix’@’localhost’ identified by ‘Zabbix_DB_Passwd’;
create database zabbix;
grant all privileges on zabbix.* to ‘zabbix’@’localhost’;
flush privileges;
exit;
Php5-fpm
Edit /etc/php5/fpm/php.ini for Zabbix
[PHP]
…..
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
……
[Date]
date.timezone = Asia/Ho_Chi_Minh
Edit [www] pool /etc/php5/fpm/pool.d/www.conf
[www]
user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
#### It depend on my server hardware, you can leave it as default ^^ #####
pm = dynamic
pm.max_children = 24
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pm.max_requests = 50000
chdir = /
Restart php5-fpm
sudo service php5-fpm restart
Nginx
In my case, this box is dedicated for Zabbix, so default site will be zabbix, Php web app root dir is in /usr/share/zabbix.
Edit /etc/nginx/sites-available/default
server {
listen 80 default_server;
root /usr/share/zabbix;
index index.php index.html index.htm;
server_name zabbix.mydomain.vn;
location / {
try_files $uri $uri/ =404;
}
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Restart Nginx
sudo service nginx restart
Zabbix-server
Init Zabbix database:
cd /usr/share/zabbix-server-mysql/
mysql -u zabbix -p zabbix < schema.sql
mysql -u zabbix -p zabbix < images.sql
mysql -u zabbix -p zabbix < data.sql
sudo cp /usr/share/doc/zabbix-frontend-php/examples/zabbix.conf.php.example /etc/zabbix/zabbix.conf.php
Edit /etc/zabbix/zabbix.conf.php
$DB[‘TYPE’] = ‘MYSQL’;
$DB[‘SERVER’] = ‘localhost’;
$DB[‘PORT’] = ‘0’;
$DB[‘DATABASE’] = ‘zabbix’;
$DB[‘USER’] = ‘zabbix’;
$DB[‘PASSWORD’] = ‘Zabbix_DB_Passwd’;
$ZBX_SERVER = ‘zabbix.mydomain.vn’;
$ZBX_SERVER_PORT = ‘10051’;
Enable Zabbix monster in /etc/default/zabbix-server
START=yes
CONFIG_FILE=”/etc/zabbix/zabbix_server.conf”
Edit /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix-server/zabbix_server.log
PidFile=/var/run/zabbix/zabbix_server.pid
DBName=zabbix
DBUser=zabbix
DBPassword=Zabbix_DB_Passwd
AlertScriptsPath=/etc/zabbix/alert.d/
FpingLocation=/usr/bin/fping
Start up Zabbix monster
service zabbix-sever restart
Zabbix-agent
Hostname is very important. It must be same with Hostname in Host Configuration in Zabbix Dashboard.
I disable ServerActive => My Zabbix agent will run in Passive mode (Server directive). The Server will open a port and then visit his Agent port 10050 and ask for his money 😀
Edit /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix-agent/zabbix_agentd.log
LogFileSize=0
Server=127.0.0.1 #Address of Zabbix Server
Hostname=zabbix.ssis.edu.vn #FQDN of monitored host
Restart Zabbix-agent
sudo service zabbix-agent restart
Zabbix Dashboard
Go to Zabbix web dashboard: http://zabbix.mydomain.vn
Defaut username: Admin
Default password: zabbix
Add host monitoring will be on next Part
Troubleshooting
MariaDB: /var/log/mysql/error.log
Nginx: /var/log/nginx/error.log
Php5-fpm: /var/log/php5-fpm.log
Zabbix-server: /var/log/zabbix-server/zabbix_server.log
More verbosity? Turn on DebugLevel=4 at /etc/zabbix/zabbix_server.conf
Reference