Can one sleep with his head facing the door?
It is fine to sleep with one’s head facing the door.
There is a custom not to sleep with one’s feet pointing towards the door, and it is said that the reason for this is that when a person who has passed away is lain awaiting burial, he is lain with his feet pointing towards the door of the room (see Gesher Hachaim I:3:2:2).
We do not wish to position ourselves when sleeping in the same position as the dead are positioned. As such, it is possible that this custom applies only when one is sleeping on the floor, and not if one is sleeping on a bed.
As to why the dead are lain with their feet pointing towards the door, this may be an extension of the custom to bury people in the cemetery with their feet pointing towards the entrance to the cemetery, which Chasam Sofer (vol 2, Y. D. 332) explains is done as an indication of the faith that we have that there will be Techiyas Hameisim (Resurrection of the Dead), as if to indicate that the dead will arise from their graves and leave the cemetery through the entrance to the cemetery.
There seems to be no reason not to sleep with one’s head towards the door.
If there is need to sleep with feet facing door, this is also permitted, and the custom above is by way of recommendation alone.