How to edit nginx.conf to increase file size upload
In case if one is using nginx proxy as a docker container (e.g. jwilder/nginx-proxy), there is the following way to configure client_max_body_size
(or other properties):
- Create a custom config file e.g.
/etc/nginx/proxy.conf
with a right value for this property - When running a container, add it as a volume e.g.
-v /etc/nginx/proxy.conf:/etc/nginx/conf.d/my_proxy.conf:ro
Personally found this way rather convenient as there's no need to build a custom container to change configs. I'm not affiliated with jwilder/nginx-proxy
, was just using it in my project, and the way described above helped me. Hope it helps someone else, too.
Add client_max_body_size
Now that you are editing the file you need to add the line into the server block, like so;
server {
client_max_body_size 8M;
//other lines...
}
If you are hosting multiple sites add it to the http context like so;
http {
client_max_body_size 8M;
//other lines...
}
And also update the upload_max_filesize
in your php.ini file so that you can upload files of the same size.
Saving in Vi
Once you are done you need to save, this can be done in vi with pressing esc
key and typing :wq
and returning.
Restarting Nginx and PHP
Now you need to restart nginx and php to reload the configs. This can be done using the following commands;
sudo service nginx restart
sudo service php5-fpm restart
Or whatever your php service is called.