Cavitation of confined fluids in nanoporous media