The extent of population mixing is known to influence the coevolutionary outcomes of many host and parasite traits, including the evolution of generalism (the ability to resist or infect a broad range of genotypes). While the segregation of populations into interconnected demes has been shown to influence the evolution of generalism, the role of local interactions between individuals is unclear. Here, we combine an individual-based model of microbial communities with a well-established framework of genetic specificity that matches empirical observations of bacterium-phage interactions. We find the evolution of generalism in well-mixed populations to be highly sensitive to the severity of associated fitness costs, but the constraining effect of costs on the evolution of generalism is lessened in spatially structured populations. The contrasting outcomes between the two environments can be explained by different scales of competition (i.e., global vs. local). These findings suggest that local interactions may have important effects on the evolution of generalism in host-parasite interactions, particularly in the presence of high fitness costs.