In systems with long-range interactions, since energy is a nonadditive quantity, ensemble inequivalence can arise: it is possible that different statistical ensembles lead to different equilibrium descriptions, even in the thermodynamic limit. The microcanonical ensemble should be considered the physically correct equilibrium distribution as long as the system is isolated. The canonical ensemble, on the other hand, can always be defined mathematically, but it is quite natural to wonder to which physical situations it does correspond. We show numerically and, in some cases, analytically that the equilibrium properties of a generalized Hamiltonian mean-field model in which ensemble inequivalence is present are correctly described by the canonical distribution in (at least) two different scenarios: (a) when the system is coupled via local interactions to a large reservoir (even if the reservoir shows, in turn, ensemble inequivalence), and (b) when the mean-field interaction between a small part of a system and the rest of it is weakened by some kind of screening.