How does nginx determine whether a file has different access paths according to its existence?

because the disk space is full and cannot be expanded directly, a disk has been added.
now intends to use nginx to determine whether the file exists, otherwise find another path.
can it be solved by using nginx, and how to configure the configuration file?
/ data1/upload/2018/08/07/1.jpg
/ data2/upload/2018/08/07/1.jpg

Apr.05,2021

location /upload/ {
    root /data1/upload/;
    try_files $uri $uri/ @data2;
}
location @data2 {
    root /data2/upload/;
    try_files $uri $uri/ =404;
}

// ...
root /data1;
location / {
    if (-e $request_filename) {
        root /data2;
        break;
    }
}
// ...

refer to

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3cedf-2c347.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3cedf-2c347.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?