I may be wrong, but I believe our dreams and nightmares are our bodies way of working through the days experiences. It's our way of processing what is happening in our lives and sometimes we need help getting over the hump. I try to go to sleep thinking happy thoughts (beach, son, something peaceful) and I don't know if it helps, but I try.
If you continue to have nightmares and are losing sleep, see your doctor. Maybe she/he can help.