I had pretty good luck with saying ouch and frowning, then immediately telling them to "touch mama gently" - take their hand and show how to touch gently. If they persist and don't remember "touch gently" after you've shown them a time or two, or if they seem to be biting out of mischief, you need to put them down, cease positive attention for a minute or two. When they do "touch gently," give lots of positive attention.
My second son was really bad about nipping, but luckily it was only me. He was especially bad about interrupting a nursing session to bite - ouch! It didn't last that long but I remember it well because it HURT. If you get the biting during nursing thing, end the session immediately and walk away, give no attention at all for a minute or two.