The influence of the interaction of Cs atoms with a dielectric surface on the position and shape of the hyperfine components of the D2 line at nanometer-order distances between atoms and the surface is studied. The use of a nanocell with a wedge-shaped gap made it possible to study the dependence of the shifts of all the hyperfine components of the D2 line corresponding to the transitions Fg = 3- Fe = 2, 3, 4 and Fg = 4- Fe = 3, 4, 5, on the distance L between the atoms and the sapphire surface windows in the range of 50–400 nm. At L less than 100 nm, due to the van der Waals interaction, there is a strong broadening of atomic transitions and a shift of their frequencies to the low-frequency region of the spectrum (red shift). The calculation of the second derivative (SD) of the vapor absorption spectra in the nanocell allows one to spectrally resolve the hyperfine components of the atomic transition down to L about 50 nm and measure the coefficient of the van der Waals interaction C3. It is shown that, at L <100 nm, an additional red shift occurs with increasing atomic density, while at relatively large distances between atoms and the surface L about 400 nm, an increase in atomic density causes a blue shift of the atomic transition frequencies. The above results are important in the development of miniature submicron devices containing atomic vapor of alkali metal.