Locke was himself sacked by Raith Rovers last month with the Scottish Championship side on a run of 15 games without a victory.
The 41-year-old inherits a side sitting seven points adrift at the foot of Scottish League Two.
Caretakers Neil Hastings and Burton O'Brien take charge for the final time against Berwick Rangers on Saturday.
But Locke will be present as the Blue Brazil look to end a run of 15 games without a win.
Cowdenbeath said in a website statement: "We ask all fans to give Gary a very warm welcome to Central Park and their full support as we face the major challenge that lies ahead in the next couple of months."
The Fife club accepted Fox's resignation as head coach on Monday.
"The club regrets that, despite Liam's great efforts and true professionalism, he was not able to bring the success we all wished for," said Cowdenbeath.
"He did face a number of challenges this season, some of which few managers would normally expect to encounter, especially in their first season in management.
"He leaves Central Park with the respect and best wishes of the chairman and all the directors of the club."
Fox, who had previously been on the coaching staff at Hearts, had taken charge at Central Park during the summer.
The 33-year-old said: "Firstly, I'd like to thank Cowdenbeath for giving me the opportunity to manage their football club.
"The experience gained and lessons learned in a short period of time will no doubt prove invaluable to me in my career."
Locke is also a former Hearts player and started his managerial career at Tynecastle before moving on to Kilmarnock then, last summer, to Stark's Park.
Gary Locke has been appointed manager of Cowdenbeath until the end of the season after the exit of Liam Fox.