Redrob2's explanation is the one usually accepted.
Say you're a moth and you want to fly west. If the moon is in the south-west, you need to fly so it's constantly ahead and to the left.
If the light you can see is the real moon, it would remain in the same direction as you fly, as it's a very long way away.
If however the light is actually a lamp a hundred metres or so away, you will soon start to fly past it, and it will seem to drift leftwards. You'll think you've veered north, and will turn left a bit to keep the light ahead and to the left. Soon it'll move some more, and you'll turn left more. As you approach it, you'll travel in a tighter and tighter spiral as you try to keep it in the right position.
The trouble with all this is that it doesn't work with all moths. Some just fly straight towards the light, and no one seems to know why -- maybe it just upsets their eyes somehow.