There are two key things I do for a fasting headache. Mine have always been from detoxing of caffeine, which give me horrible migraine type headaches.
On only one occasion I had to take ibupofen on day 2 to get rid of the pain. I was able to keep fasting 10 days. Usually they are not as bad as this one particular headache. It was so painful it almost compared to my natural birth.
That being said ... the other times I feel a headache coming on I have to be proactive.
First I get a hot pad (I have one I can microwave to get warm). I set it over my eyes and/or around my neck. I lay in a dark room for several hours and nap. This usually helps and I have to repeat it throughout the day. I often follow it with massage.
Second ... sleep seems to be key for me. I have to sleep a lot in the first couple of days.
Third ... Sun ... I try to get lots of sun on my skin. Not sure why but it seems to minimize the pain. It has helped on several occasions when I first start a fast.
Really sleep is key ... it seems to get me through the rough couple days and then the fast goes so much smoother.