Context : Aims : Analyse the distribution of matter around the progenitor star of gamma-ray burst GRB 021004 as well as the properties of its host galaxy with high-resolution echelle as well as near-infrared spectroscopy . Methods : Observations were taken by the 8.2m Very Large Telescope with the Ultraviolet and Visual Echelle spectrograph ( UVES ) and the Infrared Spectrometer And Array Camera ( ISAAC ) between 10 and 14 hours after the onset of the event . Results : We report the first detection of emission lines from a GRB host galaxy in the near-infrared , detecting H \alpha and the [ O III ] doublet . These allow an independent measurement of the systemic redshift ( z = 2.3304 \pm 0.0005 ) which is not contaminated by absorption as the Ly \alpha line is , and the deduction of properties of the host galaxy . From the visual echelle spectroscopy , we find several absorption line groups spanning a range of about 3,000 km s ^ { -1 } in velocity relative to the redshift of the host galaxy . The absorption profiles are very complex with both velocity-broadened components extending over several 100 km s ^ { -1 } and narrow lines with velocity widths of only \sim 20 km s ^ { -1 } . By analogy with QSO absorption line studies , the relative velocities , widths , and degrees of ionization of the lines ( “ line-locking ” , “ ionization–velocity correlation ” ) show that the progenitor had both an extremely strong radiation field and several distinct mass loss phases ( winds ) . Conclusions : These results are consistent with GRB progenitors being massive stars , such as Luminous Blue Variables ( LBVs ) or Wolf–Rayet stars , providing a detailed picture of the spatial and velocity structure of the GRB progenitor star at the time of explosion . The host galaxy is a prolific star-forming galaxy with a SFR of \sim 40 M _ { \odot } yr ^ { -1 } .