Optical generation of magnetic fields at the nanometric scale