Up to now, nonlocal strain gradient theory (NSGT) is broadly applied to examine free vibration, static bending and buckling of nanobeams. This theory captures nonlocal stress field effects together with the microstructure-dependent strain gradient effects. In this study, forced vibrations of NSGT nanobeams on elastic substrate subjected to moving loads are examined. The nanobeam is made of functionally graded material (FGM) with even and uneven porosity distributions inside the material structure. The graded material properties with porosities are described by a modified power-law model. Dynamic deflection of the nanobeam is obtained via Galerkin and inverse Laplace transform methods. The importance of nonlocal parameter, strain gradient parameter, moving load velocity, porosity volume fraction, type of porosity distribution and elastic foundation on forced vibration behavior of nanobeams are discussed.