In this study, a high-order compact (HOC) scheme for solving the convection–diffusion equation (CDE) under a nonuniform grid setting is developed. To eliminate the difficulty in dealing with convection terms through traditional numerical methods, an upwind function is provided to turn the steady CDE into its equivalent diffusion equation (DE). After obtaining the HOC scheme for this DE through an extension of the optimal difference method to a nonuniform grid, the corresponding HOC scheme for the steady CDE is derived through converse transformation. The proposed scheme is of the upwind feature related to the convection–diffusion phenomena, where the convective–diffusion flux in the upstream has larger contributions than that in the downstream. Such a feature can help eliminate nonphysical oscillations that may often occur when dealing with convection terms through traditional numerical methods. Two examples have been presented to test performance of the proposed scheme. Under the same grid settings, the proposed scheme can produce more accurate results than the upwind-difference, central-difference, and perturbational schemes. The proposed scheme is suitable for solving both convection- and the diffusion-dominated flow problems. In addition, it can be extended for solving unsteady CDE. It is also revealed that efforts in optimizing the grid configuration and allocation can help improve solution accuracy and efficiency. Consequently, with the proposed method, solutions under nonuniform grid settings would be more accurate than those under uniform manipulations, given the same number of grid points.