SKOPJE, Macedonia (AP) -- As hundreds of thousands of migrants flow into Europe, Macedonia finds itself an unwilling bouncer on the continent's outer fringes.
It all starts at Border Checkpoint 59, an aptly drab name for an opening in a fence on a bare, rubbish-strewn field, traversed by double tracks that form the tiny Balkan country's only rail link with Greece, the European entry point for most migrants.
More than half a million people have passed through here this year, beginning their arduous trek through the Balkans to a hoped-for better life in a wealthy European country.
Few spend longer in Macedonia than the five-hour trip by train to Serbia. The journey then takes them through Serbia, Croatia, Slovenia and Austria, to their final destination of Germany or Scandinavia.
But for the past few weeks, many have found Macedonia's gates closed.
After countries further north on the Balkan corridor decided to admit only people from designated war zones --- Syrians, Afghans and Iraqis --- Macedonia was forced to follow suit or play host to thousands of stranded and discontented migrants.
To ease the task of keeping out people of all other nationalities --- presumed to be economic migrants --- the country is building a three-meter (10-foot) high fence along its southern border with Greece, where most migrants heading for Europe arrive in decrepit boats from Turkey.
So far, the army has erected 5 kilometers (3 miles) of the fence that will eventually stretch for up to 40 kilometers (25 miles) --- covering the easiest crossing points on the 200-kilometer (120-mile) border.
Practically all migrants head for checkpoint 59, as it is near the town of Gevgelija, the departure point for the trains that will carry them to Serbia. The crossing is heavily guarded by riot police, who have been kept on their toes for more than a week.
Thousands of excluded migrants from Algeria, Tunisia, Lebanon, Morocco, Yemen, Iran, Pakistan, Bangladesh, Somalia and Congo have been crowding outside the checkpoint, angrily demanding entry, blocking rail freight services and periodically preventing refugees from reaching the crossing.
Last month dozens attacked Macedonian police with stones, enraged by fence-construction work, and the serious injury of a Moroccan youth who was electrocuted while trying to climb onto a train. Another Moroccan died in a similar accident last week, and new clashes also broke out between migrants and refugees, while Greek police used tear gas to clear a group of Iranians who had barricaded themselves outside the checkpoint to prevent refugees from crossing.
Others refused entry by Macedonia turned back to Athens, including Hamza, a 17-year-old from Morocco who gave up after 10 days at the border, defeated by cold and hunger.
"There are no jobs in Morocco, life is very bad there, we have no money and cannot stay there," he told The Associated Press in Thessaloniki, northern Greece. "We will try to go to Europe again."
Until this summer, migrants entered Macedonia clandestinely, making their way north along railway lines --- 14 people were killed in April by a train --- or highways. That changed in June, when the conservative-led government issued three-day transit papers to all migrants, enabling them to cross the country by train, bus or even taxi.
Despite initial backlogs, the system worked smoothly until the decision to exclude suspected economic migrants. Macedonia is redoubling identity checks to eliminate fake refugees.
Officials also fear that economic migrants will increasingly try to rush police or sneak in through unfenced parts of the border.
President Gjorge Ivanov has sharply criticized the European Union and Greece --- with which the country has a long-festering dispute over Macedonia's official name --- for lack of financial support and data sharing.
"In spite of the promises, Macedonia has not received any financial or technical assistance from the European Union regarding this migrant and refugee crisis," Ivanov said, saying his country has spent more than 10 million euros on migrant-related security alone.
"We face a lack of material and technical capacities as well as human resources in order to respond to the threats and risks to our national security," he said.
Ivanov said Macedonia, which is not an EU member, can shelter about 2,000 economic migrants in temporary transit centers.
"Any increase in these numbers will increase permanent and direct threats and risks for the national security of Macedonia," he said. "The risk of possible conflict between refugees and migrants, migrants and police and army, or between migrants and local people is high."
Activist Jasmin Rexhepi, who heads the Legis human rights group that works with migrants, says Greece is not doing enough to screen migrants and stop fake asylum-seekers.
"Macedonia cannot be the only defender of the EU boundaries," he told The Associated Press.
"This is a small country and has no capacity to do that. Greece ... is the first European country where migrants are making their entry," he said. "Its task ... is to make the first selection, to fully register the migrants and to control the flow."
Macedonian Foreign Minister Nikola Poposki urged EU leaders to find a comprehensive solution to the crisis.
"The problem," he said, "is that no one in Europe at the moment has willingness to openly say what (EU) policy is."