This paper presents topology optimization of capillary, the typical two-phase flow with immiscible fluids, where the level set method and diffuse-interface model are combined to implement the proposed method. The two-phase flow is described by the diffuse-interface model with essential no slip condition imposed on the wall, where the singularity at the contact line is regularized by the molecular diffusion at the interface between two immiscible fluids. The level set method is utilized to express the fluid and solid phases in the flows and the wall energy at the implicit fluid-solid interface. Based on the variational procedure for the total free energy of two-phase flow, the Cahn-Hilliard equations for the diffuse-interface model are modified for the two-phase flow with implicit boundary expressed by the level set method. Then the topology optimization problem for the two-phase flow is constructed for the cost functional with general formulation. The sensitivity analysis is implemented by using the continuous adjoint method. The level set function is evolved by solving the Hamilton-Jacobian equation, and numerical test is carried out for capillary to demonstrate the robustness of the proposed topology optimization method. It is straightforward to extend this proposed method into the other two-phase flows with two immiscible fluids.