The southeastern Imo state police said all the girls were between 14 and 17 years old and that 11 small children were also found in the house.
Some locals believed the building called the Ahamefula Motherless Babies Home served as an orphanage and shelter for expecting mothers.
Acting on a tip-off, a special unit of the Imo State police command raided the illegal home in Umuaka on Wednesday and rescued 17 girls, aged between 14 and 17, at different stages of pregnancies.
The girls claimed they were fed once a day and were not allowed to leave the home.
The girls told police that their babies were to be sold to “willing buyers.
It was not clear if the girls were brought to the home by force.
The girls further told police that they had been impregnated by a 23-year-old man who is currently in custody, along with the security guard who worked at the compound.
In a human trafficking report released last month, the European Union identified Nigeria as the African country where the scourge is most common.
The report said the selling of children was widespread and Nigerian police have previously uncovered so-called baby factories.
In May of 2011 in southeastern Abia state, police freed 32 pregnant girls who said they had been offered to sell their babies for between 25,000 and 30,000 naira (191 dollars), depending on the sex of the baby.
Another 17 pregnant girls were discovered in southern Anambra state in October 2011 under similar circumstances.
The UNESCO has previously identified human trafficking as the third most common crime in Nigeria, behind fraud and drug trafficking.