Mexican President Enrique Peña Nieto signed legislation opening up the country's oil, gas, and electricity industries to foreign and domestic private investors, amid widespread opposition.