Captive Universe (1969) by Harry Harrison...?
The synopsis on the Wikipedia page indicates that the main character is Chimal, a member of one of two tribes living within an isolated valley, and separated from one another by a river. There's a strict ban on intermarriage between the two villages, and it's believed that the river is guarded by Coatlicue, a two-headed serpent goddess. Chimal later escapes his village, and discovers that 'Coatlicue' is a machine, and that both tribes are living aboard a huge generation ship.
Chimal is a young Aztec tribesman living in an isolated valley which was sealed off from the rest of the world in ages past by a massive earthquake. Unlike the rest of his people, who are content with the way things are, he shows more interest in what lies outside the valley, and in asking questions that no one can answer. Indeed, he is altogether brighter; more intelligent than others, which often gets him into trouble, and makes him seem "unusual" to his peers.
The valley is home to two villages, one on each side of the river that flows through the middle, Quilapa (Chimal's village) and Zaachila, both of which share a temple staffed with priests who perform holy duties and interpret the laws of the Gods. This includes a ban on intermarriage between the two villages, which is strictly observed. Despite this, Chimal's mother conceived Chimal by a man from Zaachila, a fact she manages to keep secret for many years.
After Chimal refuses to marry his intended bride, and the chief priest dies of a stroke following the ensuing argument, he is arrested by the priests and condemned to sacrificial death. The Gods, angry at the sacrilege, cause the sun to fail to rise at dawn, and in the panic he is rescued by his mother, who takes his place in the cell where he is held. Before he leaves, she reveals who his real father was.
Escaping, he attempts to find a way out of the valley, while avoiding being hunted by the priests, and Coatlicue, the dreaded two-headed serpent-Goddess who stalks the land at night and kills those who foolishly wander near the river past sunset.
When he finally manages to break through the blockage at the end of the valley, Chimal finds himself in a series of many strange tunnels. He is also surprised when he meets Coatlicue, whom he followed in, in a deactivated state, and thus harmless. Travelling on, he finally meets a stranger, a woman called Watchman Steel; forcing her to lead him on, he ends up meeting more.
After initial misunderstandings, Chimal meets the Master Observer, who hails him as the "First Arriver"; he then learns the secret of the conspiracy which has been perpetrated against his people for centuries. The valley is merely the central cavity of a huge generation ship. The Aztecs are its passengers, tended by the ship's crew in the caverns, the Observers, on a centuries-long flight to Proxima Centauri, the nearest star to our sun.
Five hundred years previously, "The Great Designer", an Earth dictator, converted the asteroid Eros into a generation starship, spinning along its axis for gravity, and sent it on its journey. Because of the enormous distance involved, and the relatively slow speed it could attain, it would be the descendants of the original passengers who would arrive. To preserve order over the centuries, the passengers were split into two distinct groups, with each group genetically engineered for low intelligence in a different way, and given the hierarchical, self-sufficient and order-loving Aztec culture. The Observers were similarly programmed, and given a monastic culture to watch over the ship and the Aztecs. On Arrival Day, the two Aztec groups would be allowed to breed together, removing the genetically programmed recessive traits and producing highly intelligent offspring able to colonise the new system.
When he is shown the control center of the ship, however, Chimal realises there is a major problem. The Observers, too rigid in their thinking to understand the planetary observations, have over-ridden the flight plan and passed Proxima Centauri. On attempting to explain their mistake to them, he is denounced and hunted as a heretic. After pursuit through the ship, he initiates the Arrival program that breaks the barrier between the two Aztec communities and releases them from the valley section of the ship, and the Observers have no choice but to accept that Arrival Day has come. The book ends with the ship due to arrive at Centauri in decades, and Chimal anticipating the day when he will, soon, have equals to talk to.
The following excerpts from the Google Books preview for the book indicate that there's an artificial sun within the ship, which moves on tracks across an artificial sky.
Raising his eyes slowly he followed the tracks across the sky, as they grew closer and closer and finally vanished into a black opening high above, up the smooth curve of the sky. He tried not to think about this or understand it.
"About the sun being a ball of burning gas? I myself have seen the sun pass close and have touched the tracks it rides upon." "That is true, but unknown even to them, this world we live in is not the world they teach about. Listen and it shall be revealed."
Whilst searching for this book, I initially found this question with a similar premise. I checked Non-Stop by Brian W. Aldiss -- the book mentioned in the accepted answer -- but it didn't seem like a close enough match.
I then looked through the Goodreads list of books about generation ships -- a link to which was also provided within the accepted answer -- focusing on books published in the 1970s or earlier, and found Captive Universe about halfway down the list.
I checked the Goodreads page, then the Google Books preview, then a review, and finally the Wikipedia page, and deemed it a strong enough match to be worth posting as an answer.