Both the biosynthesis and array of bioactive and medicinal compounds in plants can be influenced by interactions with endophytic and exogenous fungi. However, the composition of endophytic and exogenous fungal communities associated with many medicinal plants is unknown, and the mechanism by which these fungi stimulate the secondary metabolism of host plants is unclear. In this study, we conducted a correlative analysis between endophytic and exogenous fungi and dendrobine and biomass accumulation in Dendrobium nobile across five Chinese habitats: wild Danxia rock, greenhouse-associated large Danxia stone, broken Danxia stone, broken coarse sandstone, and wood spile. Across habitats, fungal communities exhibited significant differences. The abundances of Phyllosticta, Trichoderma, and Hydropus were higher in wild habitats than in greenhouse habitats. Wild habitats were host to a higher diversity and richness of exogenous fungi than were greenhouse habitats. However, there was no significant difference in endophytic fungal diversity between habitats. The differences between the fungal communities' effects on the dendrobine content and biomass of D. nobile were attributable to the composition of endophytic and exogenous fungi. Exogenous fungi had a greater impact than endophytic fungi on the accumulation of fresh weight (FW) and dendrobine in D. nobile. Furthermore, D. nobile samples with higher exogenous fungal richness and diversity exhibited higher dendrobine content and FW. Phyllosticta was the only genus to be significantly positively correlated with both FW and dendrobine content. A total of 86 strains of endophytic fungi were isolated from the roots, stems, and leaves of D. nobile, of which 8 strains were found to be symbiotic with D. nobile tissue-cultured seedlings. The strain DN14 (Phyllosticta fallopiae) was found to promote not only biomass accumulation (11.44%) but also dendrobine content (33.80%) in D. nobile tissue-cultured seedlings. The results of this study will aid in the development of strategies to increase the production of dendrobine in D. nobile. This work could also facilitate the screening of beneficial endophytic and exogenous fungal probiotics for use as biofertilizers in D. nobile.