This commit is contained in:
Ferdinand Thiessen 2025-10-15 02:48:04 +05:30 committed by GitHub
commit facb720029
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 12 deletions

View File

@ -125,22 +125,32 @@ server {
access_log off;
}
# Make a regex exception for `/.well-known` so that clients can still
# access it despite the existence of the regex rule
# `location ~ /(\.|autotest|...)` which would otherwise handle requests
# for `/.well-known`.
location ^~ /.well-known {
# Service Discovery for well-known services
# (Do not allow the browse the directory).
location = /.well-known { return 403; }
location = /.well-known/ { return 403; }
location ^~ /.well-known/ {
# Using the special prefix syntax (`location ^~ /.well-known/` rather than `location /.well-known/` prevent
# the regex evaluation of other location entries (e.g. `location ~ /(\.|autotest|...)`), which would take
# precedence over this prefix. See https://nginx.org/en/docs/http/ngx_http_core_module.html#location
# The rules in this block are an adaptation of the rules
# in `.htaccess` that concern `/.well-known`.
location = /.well-known/carddav { return 301 /remote.php/dav/; }
location = /.well-known/caldav { return 301 /remote.php/dav/; }
location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
location /.well-known/pki-validation { try_files $uri $uri/ =404; }
location = /.well-known/acme-challenge { return 404; }
location /.well-known/acme-challenge/ { try_files $uri =404; }
location = /.well-known/pki-validation { return 404; }
location /.well-known/pki-validation/ { try_files $uri =404; }
# Add other exceptions/redirects here if you have other applications that provide a well known service
# Let Nextcloud's API for `/.well-known` URIs handle all other
# requests by passing them to the front-end controller.
# (use permanent redirect as it can be assumed that no new well-known service is provided
# by another application, given that Nextcloud is installed in the webroot.)
return 301 /index.php$request_uri;
}

View File

@ -61,19 +61,34 @@ server {
access_log off;
}
location ^~ /.well-known {
# Service Discovery for well-known services
# (Do not allow the browse the directory).
location = /.well-known { return 403; }
location = /.well-known/ { return 403; }
location ^~ /.well-known/ {
# Using the special prefix syntax (`location ^~ /.well-known/` rather than `location /.well-known/` prevent
# the regex evaluation of other location entries, which would take precedence over this prefix.
# See https://nginx.org/en/docs/http/ngx_http_core_module.html#location
# Although not strictly necessary within the context of this example (as the colliding rule, e.g. `location ~ /(\.|autotest|...)`,
# is now in the subfolder), some other pre-existing or future locations might still have such a rule.
# The rules in this block are an adaptation of the rules
# in the Nextcloud `.htaccess` that concern `/.well-known`.
location = /.well-known/carddav { return 301 /nextcloud/remote.php/dav/; }
location = /.well-known/caldav { return 301 /nextcloud/remote.php/dav/; }
location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
location /.well-known/pki-validation { try_files $uri $uri/ =404; }
location = /.well-known/acme-challenge { return 404; }
location /.well-known/acme-challenge/ { try_files $uri =404; }
location = /.well-known/pki-validation { return 404; }
location /.well-known/pki-validation/ { try_files $uri =404; }
# Add other exceptions/redirects here if you have other applications that provide a well known service
# Let Nextcloud's API for `/.well-known` URIs handle all other
# requests by passing them to the front-end controller.
return 301 /nextcloud/index.php$request_uri;
# (use temporary redirect in case new well-known service is provided by another application.)
return 302 /nextcloud/index.php$request_uri;
}
location ^~ /nextcloud {

View File

@ -51,7 +51,6 @@ The configuration differs from the "Nextcloud in webroot" configuration above in
- The string ``/nextcloud`` is prepended to all prefix paths.
- 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``.
- 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.
- 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.
.. literalinclude:: nginx-subdir.conf.sample
:language: nginx