I'm a little surprised that no one has already mentioned this, but getting a window seat and leaning against the side of the cabin is helpful for overcoming this situation, since it allows you to have a more reclined angle for sleeping. Of course, this will depend on the aircraft. It works much better in a big, wide-body jet where the walls are a reasonable approximation of vertical than it does on tiny regional jets where the curvature of the cabin causes it to protrude inward at head level. I've done this many times on 737-size and up aircraft, though. It works reasonably well. An added bonus is that you don't have to lean your seat back much (or at all,) which will be appreciated by the person behind you on densely-packed domestic or regional configuration cabins that don't have much seat pitch. That part doesn't matter as much on long flights where everyone is expected to lean back (and which usually have accordingly-larger seat pitch,) though. The biggest downside to this is probably turbulence. The side of the cabin doesn't have as much isolation to dampen turbulence as your seat has, so you'll definitely feel that more. I usually try to use a pillow or folded up blanket between my head and the side of the cabin to help dampen the turbulence (and to keep from hitting my head on the side of the cabin in the event of more severe turbulence.)
Barring that possibility, in aircraft that have adjustable headrests that fold out on either side (or which have permanent protrusions on either side,) I've found it helpful to sit somewhat diagonally in the chair with my head turned to the side, so that the side of my face is laying on the back of the headrest and my forehead is held from falling forwards by the side protrusion of the headrest. Of course, make sure that you don't turn your body so far to the side that your legs are encroaching on someone else's space, though (this limitation prevents me from turning very much, since my legs are relatively long.)
Of course, the best solution is to get a seat that lies completely flat in business or first class, but I'm guessing that's not an option for most people looking up answers to this question (and usually isn't an option for me, either.)