11upstream php-handler {
22 server php:9000;
3+ #server unix:/var/run/php/php7.4-fpm.sock;
34}
45
56server {
67 listen 80;
7- return 301 https://$host$request_uri;
8+ listen [::]:80;
9+
10+ # Enforce HTTPS
11+ return 301 https://$server_name$request_uri;
812}
913
1014server {
11- listen 443 ssl http2;
15+ listen 443 ssl http2;
16+ listen [::]:443 ssl http2;
1217
1318 # Use Mozilla's guidelines for SSL/TLS settings
1419 # https://mozilla.github.io/server-side-tls/ssl-config-generator/
1520 # NOTE: some settings below might be redundant
1621 ssl_certificate /etc/nginx/certs/cert.pem;
1722 ssl_certificate_key /etc/nginx/certs/key.pem;
1823
19- # Add headers to serve security related headers
20- # Before enabling Strict-Transport-Security headers please read into this
21- # topic first.
22- #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
23- #
24+ # HSTS settings
2425 # WARNING: Only add the preload option once you read about
2526 # the consequences in https://hstspreload.org/. This option
2627 # will add the domain to a hardcoded list that is shipped
2728 # in all major browsers and getting removed from this list
2829 # could take several months.
29- add_header Referrer-Policy "no-referrer" always;
30- add_header X-Content-Type-Options "nosniff" always;
31- add_header X-Download-Options "noopen" always;
32- add_header X-Frame-Options "SAMEORIGIN" always;
33- add_header X-Permitted-Cross-Domain-Policies "none" always;
34- add_header X-Robots-Tag "none" always;
35- add_header X-XSS-Protection "1; mode=block" always;
30+ #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
31+
32+ # set max upload size and increase upload timeout:
33+ client_max_body_size 512M;
34+ client_body_timeout 300s;
35+ fastcgi_buffers 64 4K;
36+
37+ # Enable gzip but do not remove ETag headers
38+ gzip on;
39+ gzip_vary on;
40+ gzip_comp_level 4;
41+ gzip_min_length 256;
42+ gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
43+ gzip_types application/atom+xml 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;
44+
45+ # Pagespeed is not supported by Nextcloud, so if your server is built
46+ # with the `ngx_pagespeed` module, uncomment this line to disable it.
47+ #pagespeed off;
48+
49+ # HTTP response headers borrowed from Nextcloud `.htaccess`
50+ add_header Referrer-Policy "no-referrer" always;
51+ add_header X-Content-Type-Options "nosniff" always;
52+ add_header X-Download-Options "noopen" always;
53+ add_header X-Frame-Options "SAMEORIGIN" always;
54+ add_header X-Permitted-Cross-Domain-Policies "none" always;
55+ add_header X-Robots-Tag "none" always;
56+ add_header X-XSS-Protection "1; mode=block" always;
3657
3758 # Remove X-Powered-By, which is an information leak
3859 fastcgi_hide_header X-Powered-By;
3960
4061 # Path to the root of your installation
4162 root /var/www/nextcloud;
4263
64+ # Specify how to handle directories -- specifying `/index.php$request_uri`
65+ # here as the fallback means that Nginx always exhibits the desired behaviour
66+ # when a client requests a path that corresponds to a directory that exists
67+ # on the server. In particular, if that directory contains an index.php file,
68+ # that file is correctly served; if it doesn't, then the request is passed to
69+ # the front-end controller. This consistent behaviour means that we don't need
70+ # to specify custom rules for certain paths (e.g. images and other assets,
71+ # `/updater`, `/ocm-provider`, `/ocs-provider`), and thus
72+ # `try_files $uri $uri/ /index.php$request_uri`
73+ # always provides the desired behaviour.
74+ index index.php index.html /index.php$request_uri;
75+
76+ # Rule borrowed from `.htaccess` to handle Microsoft DAV clients
77+ location = / {
78+ if ( $http_user_agent ~ ^DavClnt ) {
79+ return 302 /remote.php/webdav/$is_args$args;
80+ }
81+ }
82+
4383 location = /robots.txt {
4484 allow all;
4585 log_not_found off;
4686 access_log off;
4787 }
4888
49- # The following 2 rules are only needed for the user_webfinger app.
50- # Uncomment it if you're planning to use this app.
51- #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
52- #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
53-
54- # The following rule is only needed for the Social app.
55- # Uncomment it if you're planning to use this app.
56- #rewrite ^/.well-known/webfinger /public.php?service=webfinger last;
89+ # Make a regex exception for `/.well-known` so that clients can still
90+ # access it despite the existence of the regex rule
91+ # `location ~ /(\.|autotest|...)` which would otherwise handle requests
92+ # for `/.well-known`.
93+ location ^~ /.well-known {
94+ # The rules in this block are an adaptation of the rules
95+ # in `.htaccess` that concern `/.well-known`.
5796
58- location = /.well-known/carddav {
59- return 301 $scheme://$host:$server_port/remote.php/dav;
60- }
61- location = /.well-known/caldav {
62- return 301 $scheme://$host:$server_port/remote.php/dav;
63- }
97+ location = /.well-known/carddav { return 301 /remote.php/dav/; }
98+ location = /.well-known/caldav { return 301 /remote.php/dav/; }
6499
65- # set max upload size
66- client_max_body_size 512M;
67- fastcgi_buffers 64 4K;
100+ location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
101+ location /.well-known/pki-validation { try_files $uri $uri/ =404; }
68102
69- # Enable gzip but do not remove ETag headers
70- gzip on;
71- gzip_vary on;
72- gzip_comp_level 4;
73- gzip_min_length 256;
74- gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
75- gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject 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;
76-
77- # Uncomment if your server is build with the ngx_pagespeed module
78- # This module is currently not supported.
79- #pagespeed off;
80-
81- location / {
82- rewrite ^ /index.php;
103+ # Let Nextcloud's API for `/.well-known` URIs handle all other
104+ # requests by passing them to the front-end controller.
105+ return 301 /index.php$request_uri;
83106 }
84107
85- location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
86- deny all;
87- }
88- location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
89- deny all;
90- }
108+ # Rules borrowed from `.htaccess` to hide certain paths from clients
109+ location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
110+ location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
111+
112+ # Ensure this block, which passes PHP files to the PHP process, is above the blocks
113+ # which handle static assets (as seen below). If this block is not declared first,
114+ # then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
115+ # to the URI, resulting in a HTTP 500 error response.
116+ location ~ \.php(?:$|/) {
117+ # Required for legacy support
118+ rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
91119
92- location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
93- fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
120+ fastcgi_split_path_info ^(.+?\.php)(/.*)$;
94121 set $path_info $fastcgi_path_info;
122+
95123 try_files $fastcgi_script_name =404;
124+
96125 include fastcgi_params;
97126 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
98127 fastcgi_param PATH_INFO $path_info;
99128 fastcgi_param HTTPS on;
100- # Avoid sending the security headers twice
101- fastcgi_param modHeadersAvailable true;
102- # Enable pretty urls
103- fastcgi_param front_controller_active true;
129+
130+ fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice
131+ fastcgi_param front_controller_active true; # Enable pretty urls
104132 fastcgi_pass php-handler;
133+
105134 fastcgi_intercept_errors on;
106135 fastcgi_request_buffering off;
107- }
108136
109- location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
110- try_files $uri/ =404;
111- index index.php;
137+ fastcgi_max_temp_file_size 0;
112138 }
113139
114- # Adding the cache control header for js, css and map files
115- # Make sure it is BELOW the PHP block
116- location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
140+ location ~ \.(?:css|js|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
117141 try_files $uri /index.php$request_uri;
118- add_header Cache-Control "public, max-age=15778463";
119- # Add headers to serve security related headers (It is intended to
120- # have those duplicated to the ones above)
121- # Before enabling Strict-Transport-Security headers please read into
122- # this topic first.
123- #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
124- #
125- # WARNING: Only add the preload option once you read about
126- # the consequences in https://hstspreload.org/. This option
127- # will add the domain to a hardcoded list that is shipped
128- # in all major browsers and getting removed from this list
129- # could take several months.
130- add_header Referrer-Policy "no-referrer" always;
131- add_header X-Content-Type-Options "nosniff" always;
132- add_header X-Download-Options "noopen" always;
133- add_header X-Frame-Options "SAMEORIGIN" always;
134- add_header X-Permitted-Cross-Domain-Policies "none" always;
135- add_header X-Robots-Tag "none" always;
136- add_header X-XSS-Protection "1; mode=block" always;
137-
138- # Optional: Don't log access to assets
139- access_log off;
142+ expires 6M; # Cache-Control policy borrowed from `.htaccess`
143+ access_log off; # Optional: Don't log access to assets
144+
145+ location ~ \.wasm$ {
146+ default_type application/wasm;
147+ }
140148 }
141149
142- location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap) $ {
150+ location ~ \.woff2? $ {
143151 try_files $uri /index.php$request_uri;
144- # Optional: Don't log access to other assets
145- access_log off;
152+ expires 7d; # Cache-Control policy borrowed from `.htaccess`
153+ access_log off; # Optional: Don't log access to assets
154+ }
155+
156+ # Rule borrowed from `.htaccess`
157+ location /remote {
158+ return 301 /remote.php$request_uri;
159+ }
160+
161+ location / {
162+ try_files $uri $uri/ /index.php$request_uri;
146163 }
147164}
0 commit comments