On Ubuntu 20.04, I ran in a problem which I don't think I resolved 100% yet. I just can't explain it. At first I had this ScriptAlias definition:
ScriptAlias /cgi-bin/ /var/www/project/cgi-bin/
After about 4h of research, I found out that somehow the cgi-bin alias path was in conflict for binary executables (.ELF files). Strangely enough, it worked just fine with a shell script, just not with a binary... So I finally tried with:
ScriptAlias /cgi/ /var/www/project/cgi-bin/
and it worked!!! Any other changes to my settings had no bearing on the results (i.e. everything was properly setup).
My definition is under a <VirtualHost ...> definition, so it should have no conflicts. But conflicts there were for sure.
Side Note
Make sure to restart each time you make changes to your settings to make sure they are effective and you are testing something expected:
$ sudo systemctl restart apache2
Not only that, if you mistype something, it's going to let you know right away.