Switching positions
Lying on your back puts pressure on your ears, which is exactly what you want to avoid while suffering from an ear infection. It is this pressure that causes pain in the middle ear and prevents you from sleeping well in the first place.
However, by regularly changing positions during sleep, you can help relieve some of this pressure and hopefully drift off that much more comfortably. As previously mentioned, sleeping upright is a good method to try, but for natural, familiar sensations, resting on your side will have the most relaxing effect.
If your ear infection is occurring in just one ear, sleep on the side of the healthy ear to avoid adding even more pressure to the affected area.