- We study the spin–lattice relaxation of the nuclear spins in a liquid or a gas entrapped in nanosized ellipsoidal cavities with paramagnetic impurities. Two cases are considered where the major axes of cavities are in orientational order and isotropically disordered. The evolution equation and analytical expression for spin lattice relaxation time are obtained which give the dependence of the relaxation time on the structural parameters of a nanocavity and the characteristics of a gas or a liquid confined in nanocavities. For the case of orientationally ordered cavities, the relaxation process is exponential. When the nanocavities are isotropically disordered, the time dependence of the magnetization is significantly non-exponential. As shown for this case, the relaxation process is characterized by two time constants. The measurements of the relaxation time, along with the information about the cavity size, allow determining the shape and orientation of the nanocavity and concentration of the paramagnetic impurities.