Rewrite rule based upon Referer

I’ve moved my static site to a new Rails/Nginx platform and I want to
redirect some old links and referers to the appropriate “new” place in
the site. Link redirection no problem of course.

But I would like to rewrite based upon Referer. I’ve looked at the
httpRefererModule but thats clearly for access control.

I don’t see a variable $referer I can use in the rewrite module.

Any clever ideas on how to do rewrite rules based upon Referer?

Thanks for any help,

–Kip