Whip scorpions also spray acid
...but out of their other end
Giant insects - and other invertebrates - have been a common feature of fantasy role-playing games since the early days. The majority are based on real-world invertebrates expanded to much larger size. The ankheg, which made its debut in first edition AD&D, is unusual in being entirely fictional. Indeed, it is an original creation of the game, with the name being made up because it sounded good, rather than deriving from some mythological or other pre-existing fictional basis. Thus, it seems a good starting point to examine the question of how giant insects in general might actually work.