For good performance of photonic devices whose working principle is based on the enhancement of electromagnetic fields obtained by confining light into dielectric resonators with dimensions in the nanometre length scale, a detailed knowledge of the optical mode structure becomes essential. However, this information is usually lacking and can only be indirectly obtained by conventional spectroscopic techniques. Here we unraveled the influence of wire size, incident wavelength, degree of polarization and the presence of a substrate on the optical near fields generated by cavity modes of individual hexagonal ZnO nanowires by combining scanning near-field optical microscopy (SNOM) with electrodynamics calculations within the discrete dipole approximation (DDA). The near-field patterns obtained with very high spatial resolution, better than 50 nm, exhibit striking size and spatial-dispersion effects, which are well accounted for within DDA, using a wavevector-dependent dipolar interaction and considering the dielectric anisotropy of ZnO. Our results show that both SNOM and DDA simulations are powerful tools for the design of optoelectronic devices able to manipulate light at the nanoscale. © 2012 The Royal Society of Chemistry.