What is the correct direction in which to sleep? Do we sleep with our legs towards the door or away from 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 placed to lay with his feet pointing towards the door of the room (see Gesher Hachaim I:3:2:2), and 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.