Cassegrain telescopes with larger apertures suffer significant optical pupil shifting errors caused by gravity and temperature gradients. This study constructs an optical model of a large Cassegrain telescope and a method to calculate and compensate its shifting error. First, the optical structure is simplified by incorporating only the most relevant telescope components, and the system optics is modeled using ray tracing. A computer-aided mounting-based method for calculating the misalignment error of primary and secondary mirrors is proposed, with the spatial position change of secondary mirrors as the input. Next, a compensation method based on the coma-free point theory of the Cassegrain system is proposed, with the main mirror’s optical axis as the reference. Finally, using a 4 m aperture telescope as an example, the gravity- and thermal-deformation-induced shifting error is simulated. Based on this simulation, the secondary mirror position is adjusted using a secondary mirror-adjustment mechanism Hexapod platform to compensate for the misalignment error. Both gravity and temperature are major causes of shift in the pupil position, with a maximum shift of 18 mm. After compensation, this shift is controlled within 1 mm. The modeling method and the simulation process mentioned in this research can also be used in the other relevant fields.