Diffuse large B-cell lymphoma (DLBCL) is an extremely heterogeneous tumor entity, which makes prognostic prediction challenging. The tumor microenvironment (TME) has a crucial role in fostering and restraining tumor development. Consequently, we performed a systematic investigation of the TME and genetic factors associated with DLBCL to identify prognostic biomarkers for DLBCL. Data for a total of 1,084 DLBCL patients from the Gene Expression Omnibus database were included in this study, and patients were divided into a training group, an internal validation group, and two external validation groups. We calculated the abundance of immune–stromal components of DLBCL and found that they were related to tumor prognosis and progression. Then, differentially expressed genes were obtained based on immune and stromal scores, and prognostic TME‐related genes were further identified using a protein–protein interaction network and univariate Cox regression analysis. These genes were analyzed by the least absolute shrinkage and selection operator Cox regression model to establish a seven-gene signature, comprising TIMP2, QKI, LCP2, LAMP2, ITGAM, CSF3R, and AAK1. The signature was shown to have critical prognostic value in the training and validation sets and was also confirmed to be an independent prognostic factor. Subgroup analysis also indicated the robust prognostic ability of the signature. A nomogram integrating the seven-gene signature and components of the International Prognostic Index was shown to have value for prognostic prediction. Gene set enrichment analysis between risk groups demonstrated that immune-related pathways were enriched in the low-risk group. In conclusion, a novel and reliable TME relevant gene signature was proposed and shown to be capable of predicting the survival of DLBCL patients at high risk of poor survival.