A mirage is a naturally occurring optical phenomenon in which light rays are bent to produce a displaced image of distant objects or the sky.
It occurs in nature due to refraction of light rays.
The light rays coming from let's say sky towards ground are continuously bend due varying refractive index of air which is due to hot air near the ground and cooler far from ground.
And the light ray bends in a concave, upward trajectory.
Once the ray reaches the viewer’s eye, the visual cortex interprets it as if it traces back along a perfectly straight "line of sight". This line is however at a tangent to the path the ray takes at the point it reaches the eye. And this gives the experience of Mirage.