We investigate the equilibrium state and the collective modes of an excitonic insulator (EI) in a Fabry-P\'erot cavity. In an EI, two bands of a semiconductor or semimetal spontaneously hybridize due to the Coulomb interaction between electrons and holes, leading to the opening of a gap. The coupling to the electromagnetic field reduces the symmetry of the system with respect to phase rotations of the excitonic order parameter from $U(1)$ to $Z_2$. While the reduction to a discrete symmetry would in general lead to a gapped phase mode and enhance the stability of the ordered phase, the coupling to the cavity leaves the mean-field ground state unaffected. Its energy remains invariant under $U(1)$ phase rotations, in spite of the lower $Z_2$ symmetry imposed by the cavity. In dipolar gauge, this can be traced back to the balancing of the linear light-matter coupling and the dipolar self-interaction at zero frequency. At nonzero frequency, however, the collective excitations do reflect the lower $Z_2$ symmetry, which shows that fluctuations beyond mean-field could play a crucial role in finding the true phase at finite temperature.