From a9e7ed3605e27dfe719fb8807e764e32b8de147c Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sat, 26 Jul 2025 11:22:01 +0200 Subject: [PATCH] Implemented flexible upload limits for wordpress and matrix :) --- .../templates/location/upload.conf.j2 | 13 +++++++++++++ roles/web-app-matrix/config/main.yml | 3 +++ roles/web-app-matrix/templates/nginx.conf.j2 | 2 ++ .../templates/synapse/homeserver.yaml.j2 | 1 + roles/web-app-matrix/vars/main.yml | 11 +++++++++-- roles/web-app-wordpress/config/main.yml | 3 ++- roles/web-app-wordpress/vars/main.yml | 2 +- 7 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 roles/srv-proxy-7-4-core/templates/location/upload.conf.j2 diff --git a/roles/srv-proxy-7-4-core/templates/location/upload.conf.j2 b/roles/srv-proxy-7-4-core/templates/location/upload.conf.j2 new file mode 100644 index 00000000..c4611b28 --- /dev/null +++ b/roles/srv-proxy-7-4-core/templates/location/upload.conf.j2 @@ -0,0 +1,13 @@ +location {{ location_upload }} { + proxy_pass http://127.0.0.1:{{ http_port }}; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + client_max_body_size {{ client_max_body_size }}; + proxy_buffering off; + proxy_request_buffering off; + proxy_read_timeout 120s; + proxy_connect_timeout 120s; + proxy_send_timeout 120s; +} \ No newline at end of file diff --git a/roles/web-app-matrix/config/main.yml b/roles/web-app-matrix/config/main.yml index 63855b2d..6432f73a 100644 --- a/roles/web-app-matrix/config/main.yml +++ b/roles/web-app-matrix/config/main.yml @@ -39,6 +39,7 @@ csp: script-src-elem: - "element.{{ primary_domain }}" - "https://cdn.jsdelivr.net" + plugins: # You need to enable them in the inventory file chatgpt: false @@ -50,6 +51,8 @@ plugins: telegram: false whatsapp: false +client_max_body_size: "15M" + domains: canonical: synapse: "matrix.{{ primary_domain }}" diff --git a/roles/web-app-matrix/templates/nginx.conf.j2 b/roles/web-app-matrix/templates/nginx.conf.j2 index 01cc60c1..93d224e5 100644 --- a/roles/web-app-matrix/templates/nginx.conf.j2 +++ b/roles/web-app-matrix/templates/nginx.conf.j2 @@ -15,4 +15,6 @@ server { {% include 'roles/srv-web-7-7-inj-compose/templates/server.conf.j2'%} {% include 'roles/srv-proxy-7-4-core/templates/location/html.conf.j2' %} + + {% include 'roles/srv-proxy-7-4-core/templates/location/upload.conf.j2' %} } \ No newline at end of file diff --git a/roles/web-app-matrix/templates/synapse/homeserver.yaml.j2 b/roles/web-app-matrix/templates/synapse/homeserver.yaml.j2 index 5167cb71..758d29fb 100644 --- a/roles/web-app-matrix/templates/synapse/homeserver.yaml.j2 +++ b/roles/web-app-matrix/templates/synapse/homeserver.yaml.j2 @@ -1,5 +1,6 @@ server_name: "{{applications | get_app_conf(application_id, 'server_name', True)}}" pid_file: /data/homeserver.pid +max_upload_size: {{ client_max_body_size }} listeners: - port: 8008 tls: false diff --git a/roles/web-app-matrix/vars/main.yml b/roles/web-app-matrix/vars/main.yml index 9899d46e..484e6f5e 100644 --- a/roles/web-app-matrix/vars/main.yml +++ b/roles/web-app-matrix/vars/main.yml @@ -1,8 +1,10 @@ --- +# General application_id: "web-app-matrix" database_type: "postgres" registration_file_folder: "/data/" -well_known_directory: "{{nginx.directories.data.well_known}}/matrix/" + +# Matrix specific matrix_synapse_version: "{{ applications | get_app_conf(application_id, 'docker.services.synapse.version', True) }}" matrix_synapse_image: "{{ applications | get_app_conf(application_id, 'docker.services.synapse.image', True) }}" matrix_synapse_name: "{{ applications | get_app_conf(application_id, 'docker.services.synapse.name', True) }}" @@ -10,4 +12,9 @@ matrix_synapse_data: "{{ applications | get_app_conf(application_id, 'docke matrix_element_version: "{{ applications | get_app_conf(application_id, 'docker.services.element.version', True) }}" matrix_element_image: "{{ applications | get_app_conf(application_id, 'docker.services.element.image', True) }}" matrix_element_name: "{{ applications | get_app_conf(application_id, 'docker.services.element.name', True) }}" -matrix_project: "{{application_id | get_entity_name }}" \ No newline at end of file +matrix_project: "{{ application_id | get_entity_name }}" + +# Webserver +well_known_directory: "{{nginx.directories.data.well_known}}/matrix/" +location_upload: "~ ^/_matrix/media/v3/" +client_max_body_size: "{{ applications | get_app_conf(application_id, 'client_max_body_size') }}" \ No newline at end of file diff --git a/roles/web-app-wordpress/config/main.yml b/roles/web-app-wordpress/config/main.yml index 09ba320a..365c05b0 100644 --- a/roles/web-app-wordpress/config/main.yml +++ b/roles/web-app-wordpress/config/main.yml @@ -1,4 +1,5 @@ -title: "Blog" # Wordpress titel +title: "Blog" # Wordpress titel +max_upload_size: "15M" # Low default upload size, because you should use Peertube for Videos and Funkwhale for Audio files plugins: wp-discourse: enabled: "{{ 'web-app-discourse' in group_names | lower }}" diff --git a/roles/web-app-wordpress/vars/main.yml b/roles/web-app-wordpress/vars/main.yml index 3e3e4a39..3f3a8f51 100644 --- a/roles/web-app-wordpress/vars/main.yml +++ b/roles/web-app-wordpress/vars/main.yml @@ -1,7 +1,7 @@ application_id: "web-app-wordpress" database_type: "mariadb" host_msmtp_conf: "{{docker_compose.directories.config}}msmtprc.conf" -wordpress_max_upload_size: "64M" +wordpress_max_upload_size: "{{ applications | get_app_conf(application_id, 'max_upload_size') }}" wordpress_custom_image: "wordpress_custom" wordpress_docker_html_path: "/var/www/html" wordpress_version: "{{ applications | get_app_conf(application_id, 'docker.services.wordpress.version', True) }}"