Hello danb35, your script already helped me a lot in the past and it is very nicely done, thank you for your effort!
I have a question regarding running nextcloud in a Freenas-jail, although I cannot use your exact script for a reason. I did, however study and borrowed a lot of it.

I completely understand that you don't want to troubleshoot problems not directly connected to your script, but perhaps you still have an idea or can point me to the right direction.
Basically I use exactly the same software-componentes as you do (jail, mariadb, caddy, redis, php-fpm etc) and bring them together to provide the nextcloud service. It's just that I use my own collection of scripts for that and that I build the ports instead of using the pre-packaged binaries.
Since a while a have the problem that the webserver presents me with an error-message instead of the nextcloud-login:
Internal Server Error
The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.
The caddy-logfile doesn't help, also the php-fpm logfile contains nothing. I tried to tune the php.ini file to log more, but it didn't change anything. Also the nextcloud.log is empty (regarding this problem). I use exactly the same config-files as you for redis, php-fpm, and caddy (however this contains other added sections as well).
The caddy-server also provides other simple webservices besides nextcloud, which continue to work. I have the suspicion that it has to do with php-fpm, or caddy and php-fpm communicating together properly. But I don't see any mistake/problem in the config/logs however and I cannot bring it to be more verbose.
It is so strange, because when I update the port from the state of the jail were still everything works (and update the Caddyfile to the new version style), to an up-to-date ports-tree, it works as long as I don't restart the jail. But the moment I do (restart the jail), it stops working and above error appears. I have a snapshot were everything still works (with Caddy v1 still), so I can revert to that after a night of failed troubleshooting.
Any comment/insight appreciated - Thanks!