From 2ac674963abfeb1bf64aba4ee6775e2988f13281 Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 5 Oct 2025 11:17:03 -0400 Subject: [PATCH] refactor: Rewrite the NGINX root configuration file for clarity Signed-off-by: Josh --- .../installation/nginx-root.conf.sample | 563 +++++++++++++----- 1 file changed, 412 insertions(+), 151 deletions(-) diff --git a/admin_manual/installation/nginx-root.conf.sample b/admin_manual/installation/nginx-root.conf.sample index c0f62e196..21a7bfaf6 100644 --- a/admin_manual/installation/nginx-root.conf.sample +++ b/admin_manual/installation/nginx-root.conf.sample @@ -1,212 +1,473 @@ -# Version 2025-07-23 +# ============================================================================== +# Nextcloud NGINX Example Configuration (v2025-09-21-v6) +# - Latest version: https://docs.nextcloud.com/server/latest/admin_manual/go.php?to=admin-nginx +# - Tested: NGINX 1.24.x/1.25.x Nextcloud 30.x/31.x +# - All 'TODO:' lines must be changed for your environment. +# ============================================================================== + +# ==== QUICK SETUP: REQUIRED CHANGES ==== +# 1) Set $nextcloud_root in section 1 +# 2) Set PHP-FPM socket/IP in section 2 +# 3) Set listen directives for your NGINX version in section 5 +# 4) Set server_name in sections 4 & 5 +# 5) Set SSL cert/key in section 5 +# REMINDER: Restart nginx after changes. + +# ============================================================================== +# 1. Variables for Maintainability +# ============================================================================== + +# TODO: Set to your Nextcloud install path +set $nextcloud_root /var/www/nextcloud; + +# Nginx does not support the rest of the "TODO" values being handled via variables. + +# ============================================================================== +# 2. Upstream PHP Handler +# ============================================================================== upstream php-handler { - server 127.0.0.1:9000; - #server unix:/run/php/php8.2-fpm.sock; + # TODO: Set to match your PHP-FPM installation. Use only one: + server 127.0.0.1:9000; # TCP socket (default) + # server unix:/run/php/php8.2-fpm.sock; # Unix socket (if used) } -# Set the `immutable` cache control options only for assets with a cache busting `v` argument +# ============================================================================== +# 3. Cache-Control Map +# ============================================================================== + +# Sets $asset_immutable based on '?v=' parameter for smarter caching of assets. map $arg_v $asset_immutable { - "" ""; - default ", immutable"; + "" ""; # No version param: no 'immutable' + default ", immutable"; # With param: add 'immutable' } +# ============================================================================== +# 4. HTTP (80): Redirect all HTTP traffic to HTTPS +# ============================================================================== + server { - listen 80; - listen [::]:80; - server_name cloud.example.com; + # TODO: Set to your domain + server_name cloud.example.com; - # Prevent nginx HTTP Server Detection - server_tokens off; + listen 80; # IPv4 + listen [::]:80; # IPv6 - # Enforce HTTPS - return 301 https://$server_name$request_uri; + server_tokens off; + + return 301 https://$server_name$request_uri; } +# ============================================================================== +# 5. HTTPS (443): Nextcloud Handling Web Server +# ============================================================================== + server { - listen 443 ssl http2; - listen [::]:443 ssl http2; - # With NGinx >= 1.25.1 you should use this instead: - # listen 443 ssl; - # listen [::]:443 ssl; - # http2 on; - server_name cloud.example.com; + # TODO: Set to your domain + server_name cloud.example.com; - # Path to the root of your installation - root /var/www/nextcloud; + # TODO: Select the set that matches your NGINX version. Use only one: - # Use Mozilla's guidelines for SSL/TLS settings - # https://mozilla.github.io/server-side-tls/ssl-config-generator/ - ssl_certificate /etc/ssl/nginx/cloud.example.com.crt; - ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key; + # NGINX =v1.25.1 (if used) + # listen 443 ssl; # IPv4 + # listen [::]:443 ssl; # IPv6 + # http2 on; # HTTP/2 - # HSTS settings - # WARNING: Only add the preload option once you read about - # the consequences in https://hstspreload.org/. This option - # will add the domain to a hardcoded list that is shipped - # in all major browsers and getting removed from this list - # could take several months. - #add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always; + # If in doubt, use