Foliar fungal endophytes are one of the most diverse guilds of symbiotic fungi found in the photosynthetic tissues of every plant lineage, but it is unclear how plant environments and leaf resource availability shape their diversity. We explored correlations between leaf nutrient availability and endophyte diversity among Pinus muricata and Vaccinium ovatum plants growing across a soil nutrient gradient spanning a series of coastal terraces in Mendocino, California. Endophyte richness decreased in plants with higher leaf nitrogen-to-phosphorus ratios for both host species, but increased with sodium, which may be toxic to fungi at high concentrations. Isolation frequency, a proxy of fungal biomass, was not significantly predicted by any of the same leaf constituents in the two plant species. We propose that stressed plants can exhibit both low foliar nutrients or high levels of toxic compounds, and that both of these stress responses predict endophyte species richness. Stressful conditions that limit growth of fungi may increase their diversity due to the suppression of otherwise dominating species. Differences between the host species in their endophyte communities may be explained by host specificity, leaf phenology, or microclimates.