Nitrite is widespread in the environment, and is frequently used as an additive to extend the shelf life of meat products. However, the excess intake of nitrite can be harmful to human health. Hence, it is very important to know and control the content of nitrite in foodstuffs. In this work, by the means of self-assembly induced by solvent evaporation, we used the amphiphilic PEO-b-PS diblock copolymers resol and cobalt nitrate as a template to synthesize ordered mesoporous CoOx/C nanocomposites. Then, the CoOx/C nanocomposites were modified on a glassy carbon electrode (GCE), which showed excellent sensitivity, good selectivity, and a wide detection range for nitrite. Through cyclic voltammetry and current–time techniques, the electrochemical performance of the GCE modified with CoOx/C nanocomposites was analyzed. Under the optimized conditions, we found that anodic currents were linearly related to nitrite concentrations with a regression equation of lp (µA) = 0.36388 + 0.01616C (R2 = 0.9987) from 0.2 µM to 2500 µM, and the detection limit was 0.05 µM. Furthermore, the electrochemical sensor behaved with high reproducibility and anti-interference ability towards various organic and inorganic ions, such as NO3−, SO42−, Cl−, COOH− (Ac−), Na+, K+, Mg2+, and NH4+. Our results indicated that these CoOx/C nanocomposites could be applied in electrochemical sensors for the rapid and sensitive detection of the food preservative nitrite.