Skip to content

Commit 403cc12

Browse files
Ma27ryantm
authored andcommitted
nixos/nextcloud: update / clean up the nginx configuration
First of all, a few cleanups were made to make it more readable: * Reordered the sections by their priority so what you're reading in Nix is also what you get in the final nginx.conf. * Unified media/asset locations Most notably, this fixes the Your web server is not properly set up to resolve "/ocm-provider/". warning since 27.1.2 where `ocm-provider` was moved from a static directory in the source tarball to a dynamic HTTP route[1]. Additionally, the following things were fixed: * The 404 checks for build/tests/etc. are now guaranteed to be before the `.php` location match and it's not implicitly relied upon Nix's internal attribute sorting anymore. * `.wasm` files are supported properly and a correct `Content-Type` is set. * For "legacy" routes (e.g. `ocs-provider`/`cron`/etc) a `rewrite` rule inside the location for fastcgi is used as recommended by upstream[2]. This also makes it easier to understand the purpose of the location itself (i.e. use fastcgi for PHP code). [1] nextcloud/documentation#11179 [2] https://docs.nextcloud.com/server/27/admin_manual/installation/nginx.html
1 parent 6b57e8e commit 403cc12

1 file changed

Lines changed: 35 additions & 17 deletions

File tree

nixos/modules/services/web-apps/nextcloud.nix

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ let
6060
mysqlLocal = cfg.database.createLocally && cfg.config.dbtype == "mysql";
6161
pgsqlLocal = cfg.database.createLocally && cfg.config.dbtype == "pgsql";
6262

63+
# https://github.com/nextcloud/documentation/pull/11179
64+
ocmProviderIsNotAStaticDirAnymore = versionAtLeast cfg.package.version "27.1.2";
65+
6366
in {
6467

6568
imports = [
@@ -1080,10 +1083,6 @@ in {
10801083
}
10811084
'';
10821085
};
1083-
"/" = {
1084-
priority = 900;
1085-
extraConfig = "rewrite ^ /index.php;";
1086-
};
10871086
"~ ^/store-apps" = {
10881087
priority = 201;
10891088
extraConfig = "root ${cfg.home};";
@@ -1108,15 +1107,23 @@ in {
11081107
try_files $uri $uri/ =404;
11091108
'';
11101109
};
1111-
"~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/)".extraConfig = ''
1112-
return 404;
1113-
'';
1114-
"~ ^/(?:\\.(?!well-known)|autotest|occ|issue|indie|db_|console)".extraConfig = ''
1115-
return 404;
1116-
'';
1117-
"~ ^\\/(?:index|remote|public|cron|core\\/ajax\\/update|status|ocs\\/v[12]|updater\\/.+|oc[ms]-provider\\/.+|.+\\/richdocumentscode\\/proxy)\\.php(?:$|\\/)" = {
1110+
"~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/)" = {
1111+
priority = 450;
1112+
extraConfig = ''
1113+
return 404;
1114+
'';
1115+
};
1116+
"~ ^/(?:\\.|autotest|occ|issue|indie|db_|console)" = {
1117+
priority = 450;
1118+
extraConfig = ''
1119+
return 404;
1120+
'';
1121+
};
1122+
"~ \\.php(?:$|/)" = {
11181123
priority = 500;
11191124
extraConfig = ''
1125+
# legacy support (i.e. static files and directories in cfg.package)
1126+
rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[s${optionalString (!ocmProviderIsNotAStaticDirAnymore) "m"}]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
11201127
include ${config.services.nginx.package}/conf/fastcgi.conf;
11211128
fastcgi_split_path_info ^(.+?\.php)(\\/.*)$;
11221129
set $path_info $fastcgi_path_info;
@@ -1132,19 +1139,30 @@ in {
11321139
fastcgi_read_timeout ${builtins.toString cfg.fastcgiTimeout}s;
11331140
'';
11341141
};
1135-
"~ \\.(?:css|js|woff2?|svg|gif|map)$".extraConfig = ''
1142+
"~ \\.(?:css|js|mjs|svg|gif|png|jpg|jpeg|ico|wasm|tflite|map|html|ttf|bcmap|mp4|webm)$".extraConfig = ''
11361143
try_files $uri /index.php$request_uri;
11371144
expires 6M;
11381145
access_log off;
1146+
location ~ \.wasm$ {
1147+
default_type application/wasm;
1148+
}
11391149
'';
1140-
"~ ^\\/(?:updater|ocs-provider|ocm-provider)(?:$|\\/)".extraConfig = ''
1150+
"~ ^\\/(?:updater|ocs-provider${optionalString (!ocmProviderIsNotAStaticDirAnymore) "|ocm-provider"})(?:$|\\/)".extraConfig = ''
11411151
try_files $uri/ =404;
11421152
index index.php;
11431153
'';
1144-
"~ \\.(?:png|html|ttf|ico|jpg|jpeg|bcmap|mp4|webm)$".extraConfig = ''
1145-
try_files $uri /index.php$request_uri;
1146-
access_log off;
1147-
'';
1154+
"/remote" = {
1155+
priority = 1500;
1156+
extraConfig = ''
1157+
return 301 /remote.php$request_uri;
1158+
'';
1159+
};
1160+
"/" = {
1161+
priority = 1600;
1162+
extraConfig = ''
1163+
try_files $uri $uri/ /index.php$request_uri;
1164+
'';
1165+
};
11481166
};
11491167
extraConfig = ''
11501168
index index.php index.html /index.php$request_uri;

0 commit comments

Comments
 (0)