Increasing Discourse's maximum attachment size
I recently wanted to allow larger files to be uploaded to my private Discourse site (running v1.2.0.beta1). It was easy enough to find the option that I needed to update—max attachment size kb—but I didn’t know what to make of the following warning:
The maximum attachment files upload size in kB. This must be configured in nginx (client_max_body_size) / apache or proxy as well.
How should I go about configuring this in nginx?
Thankfully, Sander Datema had already provided an answer. To increase the maximum attachment size to 5 MB, I just needed to add the following commands at the end of /var/discourse/containers/app.yml
: 1
- replace:
filename: "/etc/nginx/conf.d/discourse.conf"
from: /client_max_body_size.+$/
to: client_max_body_size 5m;
Here are those same lines with a bit more context:
## Remember, this is YAML syntax - you can only have one block with a name
run:
- exec: echo "Beginning of custom commands"
- replace:
filename: "/etc/nginx/conf.d/discourse.conf"
from: /client_max_body_size.+$/
to: client_max_body_size 5m;
## If you want to configure password login for root, uncomment and change:
#- exec: apt-get -y install whois # for mkpasswd
## Use only one of the following lines:
#- exec: /usr/sbin/usermod -p 'PASSWORD_HASH' root
#- exec: /usr/sbin/usermod -p "$(mkpasswd -m sha-256 'RAW_PASSWORD')" root
## If you want to authorized additional users, uncomment and change:
#- exec: ssh-import-id username
#- exec: ssh-import-id anotherusername
- exec: echo "End of custom commands"
- exec: awk -F\# '{print $1;}' ~/.ssh/authorized_keys | awk 'BEGIN { print "Authorized SSH keys for this container:"; } NF>=2 {print $NF;}'
To apply the new settings, I ran the following command from the /var/discourse/
directory while signed in as a user with sudo privileges:
$ sudo ./launcher rebuild app
(I generally prefer to run commands via sudo instead of as root
.)
It took some time for the script to rebuild the Discourse container—a process that involves destroying the old container, bootstrapping a new container based on a template, and finally starting the new container—but it appears to have worked!
-
Note that
app.yml
is written in a custom domain-specific language (DSL) developed by Sam Saffron. From Discourse in a Docker container:While working on the process I came up with my own DSL for bootstrapping my Discourse images. I purpose built it so it solves the main issues I was hitting with a simple shell script. Multiline replace is hard in Awk and Grep. The syntax is scary to some, merging yaml files is not something you really could do that easily in a shell script.
pups makes these problems quite easy to solve
run: - replace: filename: "/etc/nginx/conf.d/discourse.conf" from: /upstream[^\}]+\}/m to: "upstream discourse { server 127.0.0.1:3000; }"
The DSL and tool lives here: https://github.com/samsaffron/pups feel free to use it where you need. I picked it over ansible cause I wanted an exact fit for my problem.