The only technique I've seen used is when the actor wears a back brace/harness and the rope is attached to the brace. There is still a little jolt, but under careful supervision it's no more dangerous than any other stunt.
Well, I doubt it's the same for movies but interestingly for theater they almost never use the harness method described by the other answers. This is because equity has decided it is too dangerous and has the potential to fail to put the actors in serious danger.
Often the trick used for equity (professional) productions is when the hanging platform is removed intending to leave the victim nowhere to stand and killing them there is actually a hidden platform below. This allows the actor to keep their feet firmly on the ground whilst making their body appear to be swinging and dying.
In this the trick lies is the rope used it has a secret mechanism which allow not to tight and also it acts as a pulley to the string attached to the top of roof no one can see.
For movies, they attach the "hanging" rope to a harness under the clothing, and the noose is just a prop. If there were close ups, then those were probably manipulated to make it appear he was strangling. People do not always release their bladders and sphincters when they die; a small portion of them do, but not everyone.