Files
nextcloud-selfhosted/nextcloud/nginx.conf
Thomas Gräfenstein a02f33e96e move text compression from Caddy to nginx for lower latency
Nginx is closer to the origin, so compressing there avoids an
extra hop. Removes the Caddy encode block for Nextcloud and adds
gzip in nginx with level 4 targeting text, CSS, JS, JSON, XML, SVG.
2026-03-22 21:08:40 +01:00

88 lines
2.7 KiB
Nginx Configuration File

upstream php-handler {
server nextcloud:9000;
}
map $uri $nonce_uri {
default "";
}
map $arg_v $asset_immutable {
"" "";
default ", immutable";
}
server {
listen 80;
server_name _;
include mime.types;
types {
application/javascript mjs;
}
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied any;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;
client_max_body_size 10G;
client_body_timeout 300s;
fastcgi_buffers 64 4K;
root /var/www/html;
index index.php index.html /index.php$request_uri;
# Redirect well-known URLs
location ^~ /.well-known {
location = /.well-known/carddav { return 301 /remote.php/dav/; }
location = /.well-known/caldav { return 301 /remote.php/dav/; }
location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
location /.well-known/pki-validation { try_files $uri $uri/ =404; }
return 301 /index.php$request_uri;
}
# Deny access to internal paths
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
# PHP handling (must be before static file locations so that internal
# redirects like /index.php/apps/theming/theme/dark.css match here
# instead of cycling back into the static file try_files)
location ~ \.php(?:$|/) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
try_files $fastcgi_script_name =404;
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_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_hide_header X-Powered-By;
fastcgi_request_buffering off;
fastcgi_max_temp_file_size 0;
}
# Serve static files directly, fall through to PHP for dynamic assets (e.g. theming)
location ~ \.(?:css|js|mjs|svg|gif|ico|jpg|png|webp|wasm|tflite|map|ogg|flac|mp4|webm)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463$asset_immutable";
access_log off;
}
location ~ \.woff2?$ {
try_files $uri /index.php$request_uri;
expires 7d;
access_log off;
}
# Default handler — route everything else through PHP front controller
location / {
rewrite ^ /index.php$request_uri last;
}
}