Optically generated magnetic fields at the nanoscale