The 31-year-old had played for Juventus since 2019, making 69 appearances for the Serie A side before being loaned to Rangers for the first six months of 2022.
Ramsey, who won three FA Cups in an eight-year spell with Arsenal, has earned 74 caps for Wales and remains the youngest man to have worn the captain's armband for his country, who are set to play in November's World Cup for the first time since 1958.
"A new chapter with Nice," he tweeted in French, before adding in English: "I can't wait to get started."
The transfer will come as a blow to Nottingham Forest and Ramsey's boyhood club Cardiff City, who had been leading the chase for his signature after his contract with Juventus was terminated.
Nice finished fifth in Ligue 1 last season and qualified for the Europa Conference League play-offs.
Ramsey will link up with former Manchester United and Everton midfielder Morgan Schneiderlin and could be joined by Leicester City goalkeeper Kasper Schmeichel, who is on the verge of joining the club.
Ramsey's new contract follows news that his compatriot Joe Rodon joined Ligue 1 rivals Rennes on loan from Spurs, with the option to make the move permanent.