We identified nanostructured devices sustaining out-of-plane nondiffracting beams with near-grazing propagation and a transverse beamwidth clearly surpassing the diffraction limit of half a wavelength. This type of device consists of a planar multilayered metal-dielectric structure with a finite number of films deposited on a solid transparent substrate. We assumed that the nondiffracting beam is launched from the substrate. The construction of the subwavelength diffraction-free beam is attended by plane waves which are resonantly transmitted through the stratified medium. Therefore, light confinement and wave amplification occurs simultaneously. We performed an optimization process concerning the layers width as free parameters in order to reach the most efficient optical resonances with uniform transmission. The value of the propagation constant and the focal placement are initially arbitrary, which can be chosen according to its practical realization. Possible applications include optical trapping, biosensing, and nonlinear optics.