The high disability rate of osteoarthritis (OA), a joint disease with an insidious onset and widespread effects, places a heavy financial burden on patients, families, and society. Traditional diagnostic approaches, including radiology and physical examination, cannot achieve early-stage screening of OA and thus, miss early intervention for patients. Therefore, the need of biomarkers for the early diagnosis of OA is crucial. In this study, we combined data from two gene expression omnibus datasets with information from OA samples, screened differentially expressed genes (DEGs) for OA using the limma package in the R software, and built a weighted gene coexpression network. After obtaining the intersecting genes, four diagnostic marker genes (FKBP5, EPYC, KLF9, and PDZRN4) highly associated with OA were screened using three machine-learning algorithms: random-forest, SVM-RFE, and LASSO. Subsequently, based on the screened signature genes, we developed a nomogram model and evaluated its diagnostic significance using calibration, DCA, and receiver operating characteristic curves. The nomogram model showed excellent predictive power and clinical value. The CIBERSORT algorithm and hallmark enrichment analysis were used to evaluate the involvement of feature genes in immune infiltration and hallmark pathways in patients with OA. The TCGA and GTEx databases provided raw data on FKBP5 expression in tumor and paracancerous samples. After further background research, immune infiltration, and functional enrichment analysis, we found that FKBP5 might play a significant role in the prognosis and immune infiltration of various cancers, and this hypothesis was validated by pancancer analysis. Correlation analysis of FKBP5 expression and drug response suggested that this gene may be a possible target for tumor therapy.