Skip to content

Commit ed7cfac

Browse files
martin-rueeggsusnux
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 e2088ac commit ed7cfac

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
@@ -119,22 +119,32 @@ server {
119119
access_log off;
120120
}
121121

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

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

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

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

admin_manual/installation/nginx-subdir.conf.sample

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

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

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

69-
location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
70-
location /.well-known/pki-validation { try_files $uri $uri/ =404; }
79+
location = /.well-known/acme-challenge { return 404; }
80+
location /.well-known/acme-challenge/ { try_files $uri =404; }
81+
location = /.well-known/pki-validation { return 404; }
82+
location /.well-known/pki-validation/ { try_files $uri =404; }
83+
84+
# Add other exceptions/redirects here if you have other applications that provide a well known service
7185

7286
# Let Nextcloud's API for `/.well-known` URIs handle all other
7387
# requests by passing them to the front-end controller.
74-
return 301 /nextcloud/index.php$request_uri;
88+
# (use temporary redirect in case new well-known service is provided by another application.)
89+
return 302 /nextcloud/index.php$request_uri;
7590
}
7691

7792
location ^~ /nextcloud {

admin_manual/installation/nginx.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ The configuration differs from the "Nextcloud in webroot" configuration above in
5151
- The string ``/nextcloud`` is prepended to all prefix paths.
5252
- 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``.
5353
- 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.
54-
- 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.
5554

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

0 commit comments

Comments
 (0)