This is going to sound like real strange way to deal with nightmares but it worked for me.
-----I had nightmares for about three years. I taught myself a technique that enabled me to remember them in great detail on waking. I wrote them all down in a book that I kept by the bed. I write Sci-fi horror and the book has given me endless inspiration when I have needed it, so something positive has come out of it. After I wrote them down in the book I shrugged them off but some were harder to shrug off than others but I got to the point where I could do it.
-----Years later, and I still look at the book when I am stuck for a story.
-----The nightmares were caused by me taking Prozac. When I stopped taking it the nightmares stopped. I named the book Prozac Dreams.