Rapid and accurate determination of soil nitrogen supply capacity by detecting nitrogen content plays an important role in guiding agricultural production activities. In this study, near-infrared hyperspectral imaging (NIR-HSI) combined with two spectral preprocessing algorithms, two characteristic wavelength selection algorithms and two machine learning algorithms were applied to determine the content of soil nitrogen. Two types of soils (laterite and loess, collected in 2020) and three types of nitrogen fertilizers, namely, ammonium bicarbonate (ammonium nitrogen, NH4-N), sodium nitrate (nitrate nitrogen, NO3-N) and urea (urea nitrogen, urea-N), were studied. The NIR characteristic peaks of three types of nitrogen were assigned and regression models were established. By comparing the model average performance indexes after 100 runs, the best model suitable for the detection of nitrogen in different types was obtained. For NH4-N, R2p = 0.92, RMSEP = 0.77% and RPD = 3.63; for NO3-N, R2p = 0.92, RMSEP = 0.74% and RPD = 4.17; for urea-N, R2p = 0.96, RMSEP = 0.57% and RPD = 5.24. It can therefore be concluded that HSI spectroscopy combined with multivariate models is suitable for the high-precision detection of various soil N in soils. This study provided a research basis for the development of precision agriculture in the future.