A couple of things. I've had headaches on and off and never really figured out why... Until a few years ago when I discovered one of my main triggers. So now I have a handful things I do and don't do.
1. Never ever eat fish or take fish oil supplements. These are almost instantaneous migraine triggers for me.
2. Never ever drink red wine even though I like it, and avoid most other alcohol.
3. Quit drinking caffeine a few hours before bedtime and make sure I drink plenty of water in the few hours before going to bed. Dehydration can trigger headaches and going to the bathroom at night is better than headaches.
4. Change beds or experiment with different bed types, including bed tilt angle (head up or down) until you find one that seems to be better than others.
5. Change pillow types. Firm, soft, thick, thin, try various ones for up to a week for each one to see if any of them help.
6. Don't sleep as long. I've found that I "feel tired" when I wake up before a full 8 hours of sleep, but if I force myself up at the 7 hour point I actually feel and function better throughout the day. Sleeping more than 8 hours feels great until the headache starts sometime between 8 and 9 hours, and then it lasts all day.
7. Try avoiding medications. Proton Pump Inhibitors (many common reflux treaments) give me night-time headaches that will wake me up at 3am and last most of the next day. If you take antacids, try switching to a different one even if they are "similar". Pepcid complete works great for me, but a similar but different one (neither of them are PPIs) doesn't work at all.
8. If you drink a lot of caffeine at any point in the day, make sure your caffeine level doesn't drop to zero. If you drink a cup of coffee in the morning, have a diet coke or something around 3 or 4 pm even if you're not tired. Better yet, ditch all stimulants.
9. As others have said, ditch all stimulants and supplements. Some of the "herbal extracts" in various legal energy drinks cause weird side effects. For example, Ginko Biloba is supposed to cause blood vessels to dilate, which can trigger headaches or other side effects.
I strongly suggest doing a very strict food experiment. Start on a Friday afternoon, eating nothing and drinking nothing but water for dinner. Saturday, eat nothing in the morning and then add ONE simple food for lunch and dinner. Make it something simple like unseasoned chicken breast or something like that. To avoid weird side effects, take a chewable vitamin (I like flintstones because other ones give me acid stomach) and add a pinch of salt to your chicken. The next day, add basic steamed white rice. The next day, add peas or broccoli. The next one fruit like apples or tomatoes.
You get the picture... One food for each day. If you ramp up to a "balanced" meal of protein, starch, and veggie by day 3, you will suffer pretty much no negative side effects other than getting really sick of eating the basic foods. But you can then add additional foods and see what happens. If you add a food and get a headache, take a step or two backwards eliminating the most recent one or two foods, and see if the symptoms go away. I was surprised by reading how many people identify long-standing food sensitivities this way, maybe gluten, egg, or milk allergies, or maybe a reaction to something as simple as the nitrates used as preservatives in processed lunch meat.
Diets like this suck and you need to be careful to add foods in a way that gets you a balanced meal asap, but unless you are diabetic or have other underlying health problems then a day or two with a reduced diet won't hurt you other than having some strange cravings.
Finally, as someone else asked... If you are overweight then consider getting no-kidding serious about reducing your BMI. Research keeps coming up with more and more reasons why being overweight is bad, and the latest is that fat cells store and produce excessive hormones and chemicals that trigger abnormal brain activity (like cravings, obsessive activity, depression, etc). Weight problems can very easily cause problems sleeping.
If all else fails and you get truly desperate, you can turn to the remedy of the ages, good old booze. I know a few people who have been amnesiacs their entire lives, but they are "functional" because they follow a very strict regimen of 2 drinks after dinner about an hour before bedtime. It's depressing and no doctor will ever recommend such a simple treatment because of how badly alcohol is abused in American society, but it's worked for hundreds, maybe thousands of years, as a sleep aid, stress reducer, and post-traumatic-event symptom reducer. Be damned careful though, because it can easily get out of control and should NEVER be combined with any sort of medication that is supposed to treat the same symptoms. If drinking, you don't get any painkillers, no anti-depressants, no sleep aids, no muscle relaxants, nothing.
Oh yea... Sometimes the simplest solution is the best. A simple muscle relaxant like skelaxin or any other relaxant with low side effects and low incidence of addition might also help. They're not cheap though.