1+ cloud.example.com # Public server hostname
2+
3+ request_body {
4+ max_size 10G
5+ }
6+
7+ # Enable gzip but do not remove ETag headers
8+ encode {
9+ zstd
10+ gzip 4
11+
12+ minimum_length 256
13+
14+ match {
15+ header Content-Type application/atom+xml
16+ header Content-Type application/javascript
17+ header Content-Type application/json
18+ header Content-Type application/ld+json
19+ header Content-Type application/manifest+json
20+ header Content-Type application/rss+xml
21+ header Content-Type application/vnd.geo+json
22+ header Content-Type application/vnd.ms-fontobject
23+ header Content-Type application/wasm
24+ header Content-Type application/x-font-ttf
25+ header Content-Type application/x-web-app-manifest+json
26+ header Content-Type application/xhtml+xml
27+ header Content-Type application/xml
28+ header Content-Type font/opentype
29+ header Content-Type image/bmp
30+ header Content-Type image/svg+xml
31+ header Content-Type image/x-icon
32+ header Content-Type text/cache-manifest
33+ header Content-Type text/css
34+ header Content-Type text/plain
35+ header Content-Type text/vcard
36+ header Content-Type text/vnd.rim.location.xloc
37+ header Content-Type text/vtt
38+ header Content-Type text/x-component
39+ header Content-Type text/x-cross-domain-policy
40+ }
41+ }
42+
43+ # Add headers to serve security related headers
44+ header Referrer-Policy no-referrer
45+ header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;"
46+ header X-Content-Type-Options nosniff
47+ header X-Download-Options noopen
48+ header X-Frame-Options SAMEORIGIN
49+ header X-Permitted-Cross-Domain-Policies none
50+ header X-Robots-Tag none
51+ header X-XSS-Protection "1; mode=block"
52+
53+ # Path to the root of your installation
54+ root * /var/www/nextcloud
55+
56+ route {
57+ # Rule borrowed from `.htaccess` to handle Microsoft DAV clients
58+ @msftdavclient {
59+ header User-Agent DavClnt*
60+ path /
61+ }
62+ redir @msftdavclient /remote.php/webdav/ temporary
63+
64+ route /robots.txt {
65+ skip_log
66+ file_server
67+ }
68+
69+ # Add exception for `/.well-known` so that clients can still access it
70+ # despite the existence of the `error @internal 404` rule which would
71+ # otherwise handle requests for `/.well-known` below
72+ route /.well-known/* {
73+ redir /.well-known/carddav /remote.php/dav/ permanent
74+ redir /.well-known/caldav /remote.php/dav/ permanent
75+
76+ @well-known-static path \
77+ /.well-known/acme-challenge /.well-known/acme-challenge/* \
78+ /.well-known/pki-validation /.well-known/pki-validation/*
79+ route @well-known-static {
80+ try_files {path} {path}/ =404
81+ file_server
82+ }
83+
84+ redir * /index.php{path} permanent
85+ }
86+
87+ @internal path \
88+ /build /build/* \
89+ /tests /tests/* \
90+ /config /config/* \
91+ /lib /lib/* \
92+ /3rdparty /3rdparty/* \
93+ /templates /templates/* \
94+ /data /data/* \
95+ \
96+ /.* \
97+ /autotest* \
98+ /occ* \
99+ /issue* \
100+ /indie* \
101+ /db_* \
102+ /console*
103+ error @internal 404
104+
105+ @assets {
106+ path *.css *.js *.svg *.gif *.png *.jpg *.jpeg *.ico *.wasm *.tflite *.map *.wasm2
107+ file {path} # Only if requested file exists on disk, otherwise /index.php will take care of it
108+ }
109+ route @assets {
110+ header /* Cache-Control "max-age=15552000" # Cache-Control policy borrowed from `.htaccess`
111+ header /*.woff2 Cache-Control "max-age=604800" # Cache-Control policy borrowed from `.htaccess`
112+ skip_log # Optional: Don't log access to assets
113+ file_server {
114+ precompressed gzip
115+ }
116+ }
117+
118+ # Rule borrowed from `.htaccess`
119+ redir /remote/* /remote.php{path} permanent
120+
121+ # Serve found static files, continuing to the PHP default handler below if not found
122+ try_files {path} {path}/
123+ file_server {
124+ pass_thru
125+ }
126+
127+ # Required for legacy support
128+ #
129+ # Rewrites all requests containing the string “.php” to be prepended by
130+ # “/index.php” unless they match a known-valid PHP file path.
131+ @unknownphppath {
132+ path /*.php /*.php/*
133+ not path \
134+ /index.php /index.php/* \
135+ /remote.php /remote.php/* \
136+ /public.php /public.php/* \
137+ /corn.php /cron.php/* \
138+ /core/ajax/update.php /core/ajax/update.php/* \
139+ /status.php /status.php/* \
140+ /ocs/v1.php /ocs/v1.php/* \
141+ /ocs/v2.php /ocs/v2.php/* \
142+ /updater/*.php /updater/*.php/* \
143+ /ocm-provider/*.php /ocm-provider/*.php/* \
144+ /ocs-provider/*.php /ocs-provider/*.php/* \
145+ /*/richdocumentscode/proxy.php /*/richdocumentscode/proxy.php/*
146+ }
147+ rewrite @unknownphppath /index.php{path}
148+
149+ # Let everything else be handled by the PHP-FPM component
150+ php_fastcgi nextcloud:9000 {
151+ env modHeadersAvailable true # Avoid sending the security headers twice
152+ env front_controller_active true # Enable pretty urls
153+ }
154+ }
0 commit comments