Sergio Ramos scored twice as Real Madrid got back on track with a 2-1 La Liga win over Malaga at the Santiago Bernabeu.