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.

What are the figures behind this? The number of police officers in England and Wales has already fallen by about 16,000 since 2010 because of cuts in Home Office funding. Labour's sums are based on assumptions about the amounts all unprotected government departments are likely to have to be cut to meet the targets for cutting the deficit, which were set out in the Budget. The Conservatives are yet to set out plans for the next three years of funding for the Home Office.
Labour says it has identified Â£800m of savings that could be made in police forces, which would prevent the loss of 10,000 jobs that it says the Conservatives would have to cut in the next three years. Labour's figures assume that all departments will be cut by the same amount. Of course, when the next government has its spending review, it could decide to make much more severe cuts to some departments than others.
Labour says it will save Â£800m by doing things such as scrapping the elections for police and crime commissioners, which are due to take place next year, and making people pay the full cost when they apply for a gun licence.
The Conservatives respond that scrapping commissioners and other measures would not save as much as Labour claims and that they have already announced plans to increase the fees for gun licences.
The biggest proposed savings come from making it compulsory for police forces to buy things together to increase their negotiating power.
The Conservatives say that already happens in a lot of cases but that Labour has overestimated the potential savings.
The Tories also point out that, despite the falls in police numbers over the past five years, crime has fallen. The two things may be unrelated and crime has been falling since the late 1990s.
So it is difficult to demonstrate either that if the Conservatives were to win the election they would cut 10,000 police staff over the next three years or indeed that Labour's plans would prevent that happening.
What this argument does highlight is how tight a timetable the next government will be working to. Departments only have spending plans laid out for a year from now.
The previous government did not manage to have a spending review until 20 October 2010. There is frantic contingency planning going on all over the civil service. And we know the police are preparing for further cuts.
What's the truth behind the politicians' claims on the campaign trail? Our experts investigate the facts, and wider stories, behind the soundbites.
Read latest updates or follow us on Twitter @BBCRealityCheck
Gary Locke has been appointed manager of Cowdenbeath until the end of the season after the exit of Liam Fox.
[NEXT_CONCEPT]
Labour says it is going to protect 10,000 police jobs, which would otherwise have been lost over the next three years.