Indonesia's Aceh looks set to cane two men who admitted having sex in contravention of Islamic laws, an official said, the first such punishment of a gay couple in the conservative province.

They face up to 100 strokes if found guilty of breaking Aceh's sharia regulations after they were caught in late March by a group of vigilantes who raided a boarding house, a spokesman for Aceh's sharia police said.

Footage of the raid in the provincial capital Banda Aceh that circulated online showed the men, aged 21 and 23, in bed as the gang burst in.

Sharia police later arrested the men who admitted being in a relationship and having had sex three times, police said.

The arrests in the western province sparked outrage among rights activists, with Human Rights Watch demanding the men's release and warning that they face "public torture for the 'crime' of their alleged sexual orientation".

"The arrest and detention of these two men underscores the abuse embedded in Aceh's discriminatory, anti-LGBT ordinances," said Phelim Kine, the group's deputy Asia director.

Aceh is the only province in the world's most populous Muslim-majority country that implements sharia.

People caught gambling and drinking alcohol have for some years been punished with public canings.

Under a local law that came into force in 2015, people can also be punished for having gay sex with up to 100 strokes of the cane.

The recently arrested men, whose identities have not been released, will be the first to be caned for breaking the regulation if the punishment goes ahead.

Gay sex is not illegal in the rest of Indonesia, which mainly follows a criminal code inherited from former colonial ruler the Netherlands.

However there was a backlash against the country's lesbian, gay, bisexual and transgender community last year with government ministers publicly making anti-gay statements.

Aceh, on Sumatra island, began implementing sharia after being granted special autonomy in 2001, an attempt by the central government to quell a long-running separatist insurgency.

Islamic laws have been strengthened since the province struck a peace deal with the government in 2005.