Why it smells
Damp places grow mold. Soap, fabric softener and lint leave a film that feeds it. The rubber seal around the door is a common trouble spot because water sits in its folds.
A closed door after every wash keeps the drum wet. That makes the problem worse.
How to clean it
Wipe the door seal with a cloth and a mild household cleaner. Pull back the folds and clean all the way around, including any gunk you find. Wipe the inside of the drum and the detergent drawer too.
Then run a hot cycle with the drum empty, using a washer cleaner or the cleaning method in your manual. Leave the door open afterward so the inside can dry. Do not mix cleaning chemicals, since some give off harmful fumes.
How to keep it from coming back
Use only the amount of detergent the label says. Too much leaves residue. Leave the door and drawer ajar between loads, and take wet clothes out soon after a cycle.
Wipe the seal now and then. A few seconds each week helps.
When it points to a drain fault
If the smell is like sewage or stale water, and the washer drains slowly or leaves water in the drum, the drain may be blocked or the pump may be failing. Cleaning the drum won't fix that.
A blocked drain can also cause leaks. Stop using the washer if water is standing in it.