The Spanish Main was the area that comprises Central America and the Northern Coast of South America. In other words, the Spanish colonies in the Americas. Ground zero for the Spanish Main would probably be Darien on the Isthmus of Panama. The land was rich in wealth, particularly gold, silver, and precious gems. When Spain wasn't trying to Christianize the natives of the area, they were raping, pillaging, and plundering. Unfortunately for Spain, most of the wealth of the Mainland was not located where ships could easily reach it. This meant the gold would be moved by pack animals to fortified ports that were built along the coast. It was at this point that Spain most vulnerable to attack. Some of the key port cities were port cities were Portobello and Darien in the area of present day Panama and Cartagena near present day Venezuela.
Of course the pirates were well aware of the methods Spain used for moving treasure and they were willing to risk the dangers of the mosquito infested swamps in order to relieve Spain of its wealth. Despite heavily armed guards, the trail through the jungle afforded ample opportunity for pirates to ambush the gold trains. The trails were narrow, and did not allow the Spaniards to maneuver. Furthermore the Pirates would often attack at dusk, after the Spaniards had had a long and arduous march through the jungle. If the ambush failed, the Pirates could melt back into the jungle, confident that the Spaniards would not follow.
(Early map of the Spanish Main)
The soldiers could not pursue the attackers for fear that the ambush was simply a diversion and that the main attack would occur after the Spanish split up their forces. In all, the pirates held the upper hand.
The gold trains would move the treasure to the fortified ports set up along the coast. These fortified ports were probably the best defended locations along the Spanish Main and also the richest. For the most part it was foolhardy to attempt an attack on such a heavily fortified area despite the riches that it contained and pirates rarely bothered to attack such a place. Of course Henry Morgan was an exception to this rule, as was Francis Drake. His most daring accomplishment was the sacking of Portobello (located in modern day Panama).It should be noted, however, that this action was done as a Privateer and with the support of a large fleet commissioned by the England.
The ports themselves had shore batteries with larger cannons than the most of the pirate ships could carry. Combine this with higher, thicker walls, and you have an area that was impervious to attack from the sea. The ports would often get the first and possible the second and third round off before the ships could even get close enough to fire. This is, of course, if you could even get that close because the Ports would also have Galleons on hand which could come out to greet you before you even got with in cannon distance of the port.
The main vulnerability in the ports was their lack of protection from the landward side. Spain assumed that the jungle was good enough protection for this area. For the most part Spain was correct.
See maps for details: (all open in a new browser window)