Skip to content

Commit 8880939

Browse files
martin-rueeggrakekniven
authored andcommitted
Elaborate on Service Discovery troubleshooting
- provide subsections for the different services and configurations - provide command line `curl` examples to debug the redirects - provide exmaple config for apache .htaccess to redirect any well known service - consistently use `NGINX` in headers, and `nginx` in text - fix some spelling/grammar Signed-off-by: Martin Rüegg <[email protected]>
1 parent 497e836 commit 8880939

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

admin_manual/installation/nginx-root.conf.sample

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,32 @@ server {
118118
access_log off;
119119
}
120120

121-
# Make a regex exception for `/.well-known` so that clients can still
122-
# access it despite the existence of the regex rule
123-
# `location ~ /(\.|autotest|...)` which would otherwise handle requests
124-
# for `/.well-known`.
125-
location ^~ /.well-known {
121+
# Service Discovery for well-known services
122+
# (Do not allow the browse the directory).
123+
location = /.well-known { return 403; }
124+
location = /.well-known/ { return 403; }
125+
location ^~ /.well-known/ {
126+
# Using the special prefix syntax (`location ^~ /.well-known/` rather than `location /.well-known/` prevent
127+
# the regex evaluation of other location entries (e.g. `location ~ /(\.|autotest|...)`), which would take
128+
# precedence over this prefix. See https://nginx.org/en/docs/http/ngx_http_core_module.html#location
129+
126130
# The rules in this block are an adaptation of the rules
127131
# in `.htaccess` that concern `/.well-known`.
128132

129133
location = /.well-known/carddav { return 301 /remote.php/dav/; }
130134
location = /.well-known/caldav { return 301 /remote.php/dav/; }
131135

132-
location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
133-
location /.well-known/pki-validation { try_files $uri $uri/ =404; }
136+
location = /.well-known/acme-challenge { return 404; }
137+
location /.well-known/acme-challenge/ { try_files $uri =404; }
138+
location = /.well-known/pki-validation { return 404; }
139+
location /.well-known/pki-validation/ { try_files $uri =404; }
140+
141+
# Add other exceptions/redirects here if you have other applications that provide a well known service
134142

135143
# Let Nextcloud's API for `/.well-known` URIs handle all other
136144
# requests by passing them to the front-end controller.
145+
# (use permanent redirect as it can be assumed that no new well-known service is provided
146+
# by another application, given that Nextcloud is installed in the webroot.)
137147
return 301 /index.php$request_uri;
138148
}
139149

admin_manual/installation/nginx-subdir.conf.sample

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,34 @@ server {
6161
access_log off;
6262
}
6363

64-
location ^~ /.well-known {
64+
# Service Discovery for well-known services
65+
# (Do not allow the browse the directory).
66+
location = /.well-known { return 403; }
67+
location = /.well-known/ { return 403; }
68+
location ^~ /.well-known/ {
69+
# Using the special prefix syntax (`location ^~ /.well-known/` rather than `location /.well-known/` prevent
70+
# the regex evaluation of other location entries, which would take precedence over this prefix.
71+
# See https://nginx.org/en/docs/http/ngx_http_core_module.html#location
72+
# Although not strictly necessary within the context of this example (as the colliding rule, e.g. `location ~ /(\.|autotest|...)`,
73+
# is now in the subfolder), some other pre-existing or future locations might still have such a rule.
74+
6575
# The rules in this block are an adaptation of the rules
6676
# in the Nextcloud `.htaccess` that concern `/.well-known`.
6777

6878
location = /.well-known/carddav { return 301 /nextcloud/remote.php/dav/; }
6979
location = /.well-known/caldav { return 301 /nextcloud/remote.php/dav/; }
7080

71-
location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
72-
location /.well-known/pki-validation { try_files $uri $uri/ =404; }
81+
location = /.well-known/acme-challenge { return 404; }
82+
location /.well-known/acme-challenge/ { try_files $uri =404; }
83+
location = /.well-known/pki-validation { return 404; }
84+
location /.well-known/pki-validation/ { try_files $uri =404; }
85+
86+
# Add other exceptions/redirects here if you have other applications that provide a well known service
7387

7488
# Let Nextcloud's API for `/.well-known` URIs handle all other
7589
# requests by passing them to the front-end controller.
76-
return 301 /nextcloud/index.php$request_uri;
90+
# (use temporary redirect in case new well-known service is provided by another application.)
91+
return 302 /nextcloud/index.php$request_uri;
7792
}
7893

7994
location ^~ /nextcloud {

admin_manual/installation/nginx.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ The configuration differs from the "Nextcloud in webroot" configuration above in
5252
- The string ``/nextcloud`` is prepended to all prefix paths.
5353
- The root of the domain is mapped to ``/var/www`` rather than ``/var/www/nextcloud``, so that the URI ``/nextcloud`` is mapped to the server directory ``/var/www/nextcloud``.
5454
- The blocks that handle requests for paths outside of ``/nextcloud`` (i.e. ``/robots.txt`` and ``/.well-known``) are pulled out of the ``location ^~ /nextcloud`` block.
55-
- The block which handles `/.well-known` doesn't need a regex exception, since the rule which prevents users from accessing hidden folders at the root of the Nextcloud installation no longer matches that path.
5655

5756
.. literalinclude:: nginx-subdir.conf.sample
5857
:language: nginx

0 commit comments

Comments
 (0)