1. Geographically distinct host populations often experience very different ecological conditions. These variable ecological conditions impact the strength of selection that these hosts experience from their parasites. 2. Numerous studies have characterized geographical patterns of resistance to infection among natural populations in the context of host-parasite local adaptation, but what other factors might contribute to these differences? 3. Here, we determined whether 20 naturally isolated populations of Drosophila melanogaster collected along the East Coast of the United States varied for survival after being inoculated with one of two species of bacteria--Lactococcus lactis and Pseudomonas aeruginosa. We then asked whether host environment accounted for the observed patterns of resistance. 4. Resistance to both types of infection varied spatially. The hosts' natural environment was predictive of the observed spatial variation in resistance to L. lactis, but not P. aeruginosa, infection. Specifically, hosts exposed to species-rich bacterial communities were more likely to survive the infection. 5. We conclude that biotic characteristics of the host environment, specifically the number of species of bacteria hosts encounter, shape host resistance to bacterial infection in nature. We discuss our results in the context of what is known about the evolutionary ecology of resistance in invertebrate systems.