Being calm and going to be with optimistic thought can indeed help, however meditation before going to sleep is just killing dreams for me.
I also had nightmares, still have, I dealt with them in this way: I usually got attacked, or see a loved one being attacked or hurted, so I fight back or die, both helped not to bring back any bad dreams again.
I used the simple "dream logic" or whatever we call it, by things being as you think, because they "used to be like that" or because "you know it's like that". So I'm working out at home, did karate for 5 years, and even though I'm far not as good as I was ( I already stopped it), I just say I can defend myself, and most of the times I can. I'm also a great shooter in real life, so shooting in dreams are also fine. These weren't always enough, so I started carrying a pocket knife in my left pocket. Even though I never used it in real life for such matters, it came to really good use in dreams, for threating if nothing else.

Soo...

Try to find something that you are good with at least a little, and empower it that you are a master of that, it should protect you, whether it's a katana, a pistol, a stick... be creative! Only thing to obey is that be confident about using whatever your choice is.

Or bring in a DC! Imgaine a DC who is always with you, or whenever you need him/her in dreams, and also imagine he/she can easily defend himself/herself and you in every situation. After that, learn that if you got into any trouble, shout his/her name to help.