  We theoretically study the spectrum induced by one and two magnetic
impurities near the boundary of a one-dimensional nanowire in proximity to a
conventional $s$-wave superconductor and extract the ground state magnetic
configuration. We show that the energies of the subgap states, supported by the
magnetic impurities, are strongly affected by the boundary for distances less
than the superconducting coherence length. In particular, when the impurity is
moved towards the boundary, multiple quantum phase transitions periodically
occur in which the parity of the superconducting condensate oscillates between
even and odd. We find that the magnetic ground state configuration of two
magnetic impurities depends not only on the distance between them but also
explicitly on their distance away from the boundary of the nanowire. As a
consequence, the magnetic ground state can switch from ferromagnetic to
antiferromagnetic while keeping the inter-impurity distance unaltered by
simultaneously moving both impurities away from the boundary. The ground state
magnetic configuration of two impurities is found analytically in the weak
coupling regime and exactly for an arbitrary impurity coupling strength using
numerical tight-binding simulations.
