From 494e1b1f6d74a8c1ef6409c1b5ea52af4206bb21 Mon Sep 17 00:00:00 2001 From: Tim de Pater Date: Mon, 23 Nov 2026 15:02:01 +0100 Subject: [PATCH] Harden nginx config for uploads and WooCommerce downloads - Deny execution of PHP files in uploads/files directories, as recommended by the WordPress nginx docs - Make WooCommerce's woocommerce_uploads directory internal so downloadable products can only be served via X-Accel-Redirect Co-Authored-By: Claude Opus 5.5 --- config/nginx.conf | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/config/nginx.conf b/config/nginx.conf index f24585bc..da20a5a9 100644 --- a/config/nginx.conf +++ b/config/nginx.conf @@ -88,6 +88,20 @@ http { add_header Cache-Control "public"; } + # Never execute PHP files in the uploads directories + # https://developer.wordpress.org/advanced-administration/server/web-server/nginx/ + location ~* /(?:uploads|files)/.*\.php$ { + deny all; + } + + # Protect WooCommerce downloadable products from direct access, + # only allow serving them through X-Accel-Redirect + # https://developer.woocommerce.com/docs/code-snippets/using_nginx_server_to_protect_your_uploads_directory/ + location ^~ /wp-content/uploads/woocommerce_uploads/ { + root /var/www; + internal; + } + location / { # First attempt to serve request as file, then # as directory, then fall back to index.php