1 # Set the `immutable` cache control options only for assets with a cache busting `v` argument
2 map $arg_v $asset_immutable {
8 server_name {{ SITE }}.{{ DOMAIN }}.{{ TLD }};
9 #disable_symlinks if_not_owner;
10 {% if ssl_ready is defined and ssl_ready %}
12 # Prevent nginx HTTP Server Detection
16 return 301 https://$server_name$request_uri;
18 access_log /home/sites/log/nginx/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/access.log main buffer=32k;
19 error_log /home/sites/log/nginx/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/error.log warn;
24 server_name {{ SITE }}.{{ DOMAIN }}.{{ TLD }};
26 # Path to the root of your installation
27 root /home/sites/data/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/nextcloud;
29 disable_symlinks if_not_owner;
30 ssl_certificate /etc/letsencrypt/live/{{ SITE }}.{{ DOMAIN }}.{{ TLD }}/fullchain.pem;
31 ssl_certificate_key /etc/letsencrypt/live/{{ SITE }}.{{ DOMAIN }}.{{ TLD }}/privkey.pem;
33 access_log /home/sites/log/nginx/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/access.log main buffer=32k;
34 error_log /home/sites/log/nginx/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/error.log warn;
36 # Prevent nginx HTTP Server Detection
40 # WARNING: Only add the preload option once you read about
41 # the consequences in https://hstspreload.{{ TLD }}/. This option
42 # will add the domain to a hardcoded list that is shipped
43 # in all major browsers and getting removed from this list
44 # could take several months.
45 add_header Strict-Transport-Security "max-age=15768000; includeSubDomains" always;
47 # set max upload size and increase upload timeout:
48 client_max_body_size 512M;
49 client_body_timeout 300s;
50 fastcgi_buffers 64 4K;
52 # Enable gzip but do not remove ETag headers
57 gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
58 gzip_types application/atom+xml text/javascript application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/wasm application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
60 # Pagespeed is not supported by Nextcloud, so if your server is built
61 # with the `ngx_pagespeed` module, uncomment this line to disable it.
64 # The settings allows you to optimize the HTTP2 bandwitdth.
65 # See https://blog.cloudflare.com/delivering-http-2-upload-speed-improvements/
67 client_body_buffer_size 512k;
69 # HTTP response headers borrowed from Nextcloud `.htaccess`
70 add_header Referrer-Policy "no-referrer" always;
71 add_header X-Content-Type-Options "nosniff" always;
72 add_header X-Download-Options "noopen" always;
73 add_header X-Frame-Options "SAMEORIGIN" always;
74 add_header X-Permitted-Cross-Domain-Policies "none" always;
75 add_header X-Robots-Tag "noindex, nofollow" always;
76 add_header X-XSS-Protection "1; mode=block" always;
78 # Remove X-Powered-By, which is an information leak
79 fastcgi_hide_header X-Powered-By;
81 # Add .mjs as a file extension for javascript
82 # Either include it in the default mime.types list
83 # or include you can include that list explicitly and add the file extension
84 # only for Nextcloud like below:
87 text/javascript js mjs;
90 location ~ /common-apps/(.*)$ {
91 alias /home/sites/data/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/common/$1;
94 location ~ /instance-apps/(.*)$ {
95 alias /home/sites/data/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/apps/$1;
98 # Specify how to handle directories -- specifying `/index.php$request_uri`
99 # here as the fallback means that Nginx always exhibits the desired behaviour
100 # when a client requests a path that corresponds to a directory that exists
101 # on the server. In particular, if that directory contains an index.php file,
102 # that file is correctly served; if it doesn't, then the request is passed to
103 # the front-end controller. This consistent behaviour means that we don't need
104 # to specify custom rules for certain paths (e.g. images and other assets,
105 # `/updater`, `/ocs-provider`), and thus
106 # `try_files $uri $uri/ /index.php$request_uri`
107 # always provides the desired behaviour.
108 index index.php index.html /index.php$request_uri;
110 # Rule borrowed from `.htaccess` to handle Microsoft DAV clients
112 if ( $http_user_agent ~ ^DavClnt ) {
113 return 302 /remote.php/webdav/$is_args$args;
117 location = /robots.txt {
123 # Make a regex exception for `/.well-known` so that clients can still
124 # access it despite the existence of the regex rule
125 # `location ~ /(\.|autotest|...)` which would otherwise handle requests
126 # for `/.well-known`.
127 location ^~ /.well-known {
128 # The rules in this block are an adaptation of the rules
129 # in the Nextcloud `.htaccess` that concern `/.well-known`.
131 location = /.well-known/carddav { return 301 /remote.php/dav/; }
132 location = /.well-known/caldav { return 301 /remote.php/dav/; }
134 location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
135 location /.well-known/pki-validation { try_files $uri $uri/ =404; }
137 # Let Nextcloud's API for `/.well-known` URIs handle all other
138 # requests by passing them to the front-end controller.
139 return 301 /index.php$request_uri;
142 # Rules borrowed from `.htaccess` to hide certain paths from clients
143 location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
144 location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
146 # Ensure this block, which passes PHP files to the PHP process, is above the blocks
147 # which handle static assets (as seen below). If this block is not declared first,
148 # then Nginx will encounter an infinite rewriting loop when it prepends
149 # `/index.php` to the URI, resulting in a HTTP 500 error response.
150 location ~ \.php(?:$|/) {
151 # Required for legacy support
152 # commented lines from nextcloud nginx template are already in /etc/nginx/conf.d/fastcgi.conf
153 rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|ocs-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
155 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
156 #set $path_info $fastcgi_path_info;
158 try_files $fastcgi_script_name =404;
160 include /etc/nginx/conf.d/fastcgi.conf;
161 #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
162 #fastcgi_param PATH_INFO $path_info;
163 fastcgi_param HTTPS on;
165 fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice
166 fastcgi_param front_controller_active true; # Enable pretty urls
168 fastcgi_param NEXTCLOUD_CONFIG_DIR /home/sites/data/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/config;
169 fastcgi_pass unix:/run/php{{ php_version }}/fpm/php_{{ SIGLE }}_{{ SITE }};
171 #fastcgi_intercept_errors on;
172 fastcgi_request_buffering off;
174 #fastcgi_max_temp_file_size 0; #2M in /etc/nginx/conf.d/fastcgi.conf
178 location ~ \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
179 try_files $uri /index.php$request_uri;
180 add_header Cache-Control "public, max-age=15778463, $asset_immutable";
181 access_log off; # Optional: Don't log access to assets
184 default_type application/wasm;
188 location ~ \.woff2?$ {
189 try_files $uri /index.php$request_uri;
190 expires 7d; # Cache-Control policy borrowed from `.htaccess`
191 access_log off; # Optional: Don't log access to assets
194 # Rule borrowed from `.htaccess`
196 return 301 /remote.php$request_uri;
200 try_files $uri $uri/ /index.php$request_uri;