I have chronic gastritis, even when I eat several hours before bed. Is there anything I can do or take to prevent this? It is unbearable..

Meds. If the diagnosis is correct, welcome! me too. Pretty annoying isn't it? The treatment is an acid blocker called a proton pump inhibitor and sometimes a pro kinetic medication that will keep food from sitting in your stomach. Sometimes you may have breakthrough symptoms. Tums, Zantac (ranitidine) or Pepcid or tagamet may give added bedtime relief. Don't smoke, stop booze, and get up and don't sit or recline foi.
See your doc. If pain is unbearable then need to see your doc or get urgent medical help. See gastroenterology for evaluation if not done and further complex management may be needed. See tags below.