Moodle™ 5.1 put the web tree in public/ . $CFG->dirroot is now that public/ directory. $CFG->root is the install root above it. $CFG->dataroot did not move. If nginx root still points at the install root, you are serving files Moodle spent a release cycle hiding.
This is a different failure from a dataroot that sits on the public hostname. Dataroot is student files. A wrong 5.1 document root is source : vendor/ , node_modules/ leftovers, config.php , composer.json , .git , upgrade scripts, and every PHP file that used to sit next to index.php .
The official note is on moodledev.io .…