I had that maybe 7-8 times in my life, generally reducing coffee consumption and avoiding it on an empty stomach is enough.
But this time I'm pretty sure I have a starting ulcer, so I'm really careful. I know it's not caused by coffee, but it certainly can make it worse, so..
But quitting cold turkey was horribly painful, I don't advise.