Hello!
Sleeping with the door open always makes people feel insecure. It's not surprising that some people like dream of the thief or strangers coming into the house, and friends in mountainous and rural areas dream of wild animals coming in. As for you often dream about ghosts, maybe you have heard too many ghost stories, and ghosts are an unsafe factor for you.
As for sleeping behind closed doors, you will feel much safer, and dreams are naturally different.
I suggest you close the door and sleep often to increase your sense of security. At the same time, don't watch horror novels, movies and the like within one hour before going to bed.