The size effect of nanoporous materials is generally believed to be caused by the large ratio of surface area to volume, so that it is also called surface effect. Based on a recently developed elastic theory, in which the surface effect of nanomaterials is characterized by the surface energy density, combined with two micromechanical models of composite materials, the surface effect of nanoporous materials is investigated. Closed-form solutions of both the effective bulk modulus and the effective shear one of nanoporous materials are achieved, which are related to the surface energy density of corresponding bulk materials and the surface relaxation parameter of nanomaterials, rather than the surface elastic constants in previous theories. An important finding is that the enhancement of mechanical properties of nanoporous materials mainly results from the compressive strain induced by nanovoid's surface relaxation. With a fixed volume fraction of nanovoids, the smaller the void size, the harder the nanoporous material will be. The results in this paper should give some insights for the design of nanodevices with advanced porous materials or structures.