diff --git a/admin_manual/installation/nginx-root.conf.sample b/admin_manual/installation/nginx-root.conf.sample index 21a7bfaf6..9df2d7bd3 100644 --- a/admin_manual/installation/nginx-root.conf.sample +++ b/admin_manual/installation/nginx-root.conf.sample @@ -2,26 +2,24 @@ # 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. +# - All lines labeled 'TODO:' 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 +# 3) Set server_name in sections 4 & 5 +# 4) Set listen directives for your NGINX version in section 5 # 5) Set SSL cert/key in section 5 -# REMINDER: Restart nginx after changes. +# Reminder: restart NGINX after making changes. # ============================================================================== -# 1. Variables for Maintainability +# 1. Variables # ============================================================================== # 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 # ============================================================================== @@ -36,7 +34,7 @@ upstream php-handler { # 3. Cache-Control Map # ============================================================================== -# Sets $asset_immutable based on '?v=' parameter for smarter caching of assets. +# Sets $asset_immutable based on the '?v=' URL parameter for smarter asset caching. map $arg_v $asset_immutable { "" ""; # No version param: no 'immutable' default ", immutable"; # With param: add 'immutable' @@ -77,7 +75,7 @@ server { # listen [::]:443 ssl; # IPv6 # http2 on; # HTTP/2 - # If in doubt, use $fastcgi_script_name=/file.php, $fastcgi_path_info=/extra/path) + # - The `.php` can be anywhere in the URI (e.g. /foo.php, /foo/bar.php, /foo.php/bar) + # - i.e. URI must either end after the `.php` or be followed immediately by a forward slash (`/`). + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + set $path_info $fastcgi_path_info; - fastcgi_split_path_info ^(.+?\.php)(/.*)$; - set $path_info $fastcgi_path_info; - - try_files $fastcgi_script_name =404; + # Ensure the target script exists; otherwise return 404 + try_files $fastcgi_script_name =404; + # FastCGI params and environment include fastcgi_params; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param PATH_INFO $path_info; - fastcgi_param HTTPS on; - fastcgi_param modHeadersAvailable true; - fastcgi_param front_controller_active true; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $path_info; + fastcgi_param HTTPS on; + fastcgi_param modHeadersAvailable true; + fastcgi_param front_controller_active true; + + # Send to configured PHP backend fastcgi_pass php-handler; - - fastcgi_intercept_errors on; - + fastcgi_intercept_errors on; } - # -------------------------------------------------------------------------- - # 5.15 Static Asset Handling (JS, CSS, images, fonts, etc.) - # -------------------------------------------------------------------------- - + # ---- Static Asset Handling (JS, CSS, images, fonts, etc.) ---- location ~ \.(?:css|js|mjs|svg|gif|ico|jpg|png|webp|wasm|tflite|map|ogg|flac)$ { try_files $uri /index.php$request_uri; # Set the HTTP Cache-Control header for different types of static assets: # Tells browsers how aggressively to cache a given asset. - # The $asset_immutable variable to dynamically set using the map in section 3 + # The $asset_immutable variable is set dynamically by the map in section 3. # Requests for assets with a 'v=' parameter are set to immutable. add_header Cache-Control "public, max-age=15778463$asset_immutable"; - # Security headers repeated from section 5.6, see there for details. - # These must be repeated here due to NGINX add_header inheritance rules: + # Security headers repeated from section 5.4. These must be repeated due to NGINX add_header inheritance rules: add_header Referrer-Policy "no-referrer" always; add_header X-Content-Type-Options "nosniff" always; add_header X-Frame-Options "SAMEORIGIN" always; @@ -419,16 +368,12 @@ server { access_log off; } - # -------------------------------------------------------------------------- - # 5.16 Redirect /remote to /remote.php (legacy compatibility) - # -------------------------------------------------------------------------- + # ---- Redirect /remote to /remote.php (legacy compatibility) ---- location /remote { return 301 /remote.php$request_uri; } - # -------------------------------------------------------------------------- - # 5.17 Fallback: Pass all other requests to the default frontend - # -------------------------------------------------------------------------- + # ---- Fallback: Pass all other requests to the default frontend ---- location / { try_files $uri $uri/ /index.php$request_uri; } @@ -467,7 +412,7 @@ server { # ============================================================================== # REMINDERS: -# - Restart nginx after changes! +# - Restart NGINX after changes! # - See testing tips at the top in QUICK SETUP. # END OF FILE # ==============================================================================