PrivateBin / docker-nginx-fpm-alpine

PrivateBin docker image based on Nginx, php-fpm & Alpine Linux stack
https://hub.docker.com/r/privatebin/nginx-fpm-alpine/
147 stars 57 forks source link

Can't override Nginx client_max_body_size 15M - Duplicate Directive #179

Closed mrnoisytiger closed 1 month ago

mrnoisytiger commented 7 months ago

I'm trying to increase my client_max_body_size by following the guidance in the README. I've added a new client_max_body_size directive and have it mounted as read-only to into the /etc/nginx/http.d/ folder as nginx.conf.

However, upon starting the Docker container, I get the following error:

2023/12/10 14:53:56 [emerg] 17#17: "client_max_body_size" directive is duplicate in /etc/nginx/http.d/nginx.conf:6
nginx: [emerg] "client_max_body_size" directive is duplicate in /etc/nginx/http.d/nginx.conf:6

This appears to be due to the same max size directive being set in the main /etc/nginx/nginx.conf but also repeated in the additional config. Would love to know how best to solve this without tinkering with the base filesystem files.

elrido commented 7 months ago

No need to modify the image. To modify files shipped in it, you will want to grab a copy of the file in question (found here), modify it, and attach it to the original location (/etc/nginx/nginx.conf) into the image. In UNIX and Linux you can mount over single files or directories as many times as needed, though normally this not done, since it wastes space (two versions of the file).

The only downside is that you may occasionally have to update the config file, should a new nginx change the config format or some of the core default settings provided in it (the same is true for our project, since we replace the version shipped by alpine).

Alternatively, you may want to have a look at the sister image that uses nginx unit instead of the nginx webserver. It's single configuration file for unit and PHP is found here. You would want to change the max_body_size as well as the two PHP settings post_max_size and upload_max_filesize and can either do so by attaching your own version into the image as /var/lib/unit/conf.json or using the configuration socket in the image at /run/control.unit.sock to push configuration changes at runtime (useful to test changes without restarting the service) - see also the section in the readme doc.