The Best is to sit down and pull from one side(rein)
First of all is your horse a young one? They usually do that because they have too much energy. To stop it, you can lunge him before you ride in order to make him unwind and be calm when you ride him.
Then, you need to stay calm, stay straight (even keep your shoulders behind if you can) to stay on and try to put his head up, you can also put him on a circle, it will be harder for him to buck.
If he does it only before cantering, anticipate his action by keeping his head up before the start (this way he won't be able to buck).
Finally, there are two ways to stop him from stopping this habit:
-push him harder when he tries to buck, if he's got impulsion he won't be able to buck,
-don't ask to canter if you see that he is hot and ready to be crazy, occupy him by doing lateral movements and try later or even te day after.
I hope i could help you :)