If you're having trouble sleeping because of persistent nightmares, take note of the following information from the U.S. National Library of Medicine, on factors that might be affecting your sleeping state:
1) Eating before bed, which can increase brain activity.
2) Any anxiety or stress.
3) Major life events, such as births or deaths.
4) Withdrawals or side effects that are caused by drugs
I have had experience with the first one... eating before bed. If it's late at night and I'm hungry, I will snack on crackers or something light to avoid nightmares.
Regarding stress, I don't get nightmares, but I don't get a good nights rest. I try and compensate by writing all my thoughts down to get them out. Sometimes it works and sometimes it doesen't; it depending on what I'm stressed about.