We have controlled the molecular orientation of nematic and smectic A liquid crystal (LC) phases in a porous anodic aluminium oxide (AAO) film, in which the pore diameter was varied from 20nm to 100nm. Surface anchoring to induce planar and homeotropic molecular arrangement was controlled by chemical modification of the AAO inner surface. Direct observation of the molecular orientation of LC phases was performed using grazing incidence X-ray diffraction technique, showing in-plane and out-of-plane molecular orientation, and the corresponding layer orientation. The systematic investigation of LC phases under nanoconfinement will be useful to design various kinds of physicochemical environments to control the orientation of other soft matters.