* UN envoys seeking to broker peace dialogue
* Rivalries spread to squabble over oil resources
* El Sharara oilfield latest battle line
By Ulf Laessing
EL SHARARA, Libya, Dec 8 (Reuters) - Deep in Libya's southern Sahara, men in army uniforms guard a pipeline at the El Sharara oilfield. Hundreds of kilometers to the north, rival fighters turn off the pumps to stop the oil flowing.
The standoff over El Sharara illustrates the complex challenge United Nations mediators face in holding together a country heading towards a civil war between factions allied with rival cities scrambling for control.
U.N. envoys plan to bring the Libyan rivals together on Tuesday for a dialogue, but the conflict is spreading with both sides increasingly at odds over the OPEC country's vast oil resources.
Since the 2011 revolution that toppled Muammar Gaddafi, Libya has enjoyed little stability. But rivalries worsened after a group called Libya Dawn seized Tripoli in August, setting up its own government and forcing the recognized Prime Minister, Abdullah al-Thinni, to flee to the east.
At El Sharara, one of the country's largest fields, guards securing its storage areas, pumps and pipes are led by officers from Misrata, a coastal city 1,000 km (600 miles) to the north and power base of Libya Dawn.
"We have been appointed by the chief of staff," said oil force commander Mohamed Esmaida, referring to the Tripoli-based rival army leadership challenging Thinni's own chief of staff.
He took over the field with around 400 guards driving Toyota pickups, a month ago after rivals from Zintan, a western region, withdrew. His men wear uniforms with "Libyan army" tags -- like many Zintan fighters.
The Zintanis, allied to Thinni, had already pulled out of the capital after a battle with Libya Dawn over the summer. Now to make sure their rivals don't benefit from the oil they have closed an El Sharara pipe valve crossing their territory.
Just 70 km (40 miles) west of El Sharara, co-owned by Spain's Repsol, lies another oilfield called El Feel run by Italy's ENI, which the self-declared Tripoli government has also been trying to restart but whose pipelines also cross Zintan territory.
Libya's conflict is broadly pitting communities from coastal cities such as Misrata against tribes in the hinterland. Both sides fought together to topple Gaddafi in 2011, but have since fought each other for control of the country.
That inter-regional conflict is further complicated by rivalries between tribes, tensions between former Gaddafi units and staunchly anti-Gaddafi adversaries, and by infighting between Islamist-leaning and nationalist forces.
Each side is also trying to win recognition from neighbours such as Egypt, Algeria and regional powers in the Middle East.
Thinni, who accuses Dawn of relying on Islamist militants, has teamed up with former Gaddafi army general Khalifa Haftar, who enjoys the support of tribes in the east and in Zintan.
The U.N. talks have so far focused on convincing the new Tripoli rulers to accept the legitimacy of the House of Representatives, the elected assembly working out of a remote city in east.
But this approach has come under pressure as the rival government has sought to consolidate power by taking over Tripoli ministries and oil facilities. Thinni has also drawn U.N. condemnation for launching air strikes on western Libya.
The U.N. Has not released any details on Tuesday's talks after launching an initial round in the southern city of Ghadames in September.
The first round invited members of the House of Representatives and lawmakers from Misrata who have boycotted the assembly but not any armed groups. U.N. Special envoy Bernadino Leon was expected in Tripoli on Monday.
A big challenge for mediators is that each side only controls parts of the vast nation, leaving large areas where few take orders from anyone.
Clashes between rival tribes have made the roads from El Sharara to the nearby cities of Ubari and Sabha too dangerous to bring in food. An air force base around 200 km (125 miles) away, controlled by Dawn, supplies the field.
"We try to minimize the manpower," said Abu Bakr Shilhab, a field manager, explaining the supply problems while a helicopter from Tamahind brings in water, Pepsi and vegetables.
The gated oilfield with its 24-hour power supply, swimming pool, gym and other amenities rare in the poor south attracts unwelcome interest from tribesmen seeking a share of the wealth.
Armed men have stormed the field three times since October 2013, forcing costly shutdowns.
"They once walked into the control room asking to turn off wells like you switch off a TV," said an oil worker. "Last month they came to steal cars."
Sitting in El Sharara's staff meeting room, commander Esmaida tells managers that his forces will make sure the field's engineers can work safely.
"We can do that," he said. "That's our job."
Whether the U.N. mediators can succeed in theirs in the present political climate remains to be seen. (Editing by Patrick Markey and Giles Elgood)