That 'nagi' is a general term for snakes, and therefore, it is a word that has the same origin as the Okinawan dialect of nagi and noga, which, respectively, mean snakes and rainbow.
「ナギ」は蛇類の総称であり、蛇・虹の意の沖縄方言ナギ・ノーガと同源の語である。