The Ephel Dúath ("Fence of Shadow") defended Mordor on the west and south. The main pass was guarded by Minas Morgul, a city built by Gondor as Minas Ithil. The fortress Durthang lay in the northern Ephel Dúath above Udûn. A higher, more difficult pass, Cirith Ungol, lay just to the north of the Morgul pass. Its top was guarded by a tower, built by Gondor.
The route traversed Torech Ungol, the lair of the giant spider Shelob.
Why would Gondor build a tower near such a powerful foe? Any men quartered there would become food for Shelob. There was no need to guard the upper pass because it was far more difficult to traverse than the main pass by Minas Morgul. Even if the pass was easy, Shelob could guard it on her own simply because she will eat any creature. She would even guard it against Sauron's forces because she was independent of him and his influence. (The sentence below from The Two Towers, says she served none but herself.)
Did Shelob enter the lair late in the Third Age after Gondor built the tower? A line from the chapter, "Shelob's Lair" in The Two Towers, says she was there before Sauron. (Not sure if that means she was there before Sauron's earlier downfall when Isildur cut the One Ring from his hand, or merely if she was there before Sauron returned to Mordor the second time.)
"But still she was there, who was there before Sauron, and before the first stone of Barad-dûr; and she served none but herself, drinking the blood of Elves and Men, bloated and grown fat with endless brooding on her feasts, weaving webs of shadow; for all living things were her food, and her vomit darkness"
Why would Gondor build a tower where every soldier sent to it could become a snack for an ancient evil?
I will vote for answers based on canon sources.