Wear a gourd.
In fact, you shouldn't deliberately think about it.
Be strong-willed when having nightmares, and tell yourself that you must wake up and shake your head hard. Learn to control your dreams. If you are not controlled by dreams, you will not be easily hypnotized.
Another way is to let nature take its course, and the nightmare will be a nightmare. Leave it alone and you will wake up naturally.
Just don't focus on this matter.