The article is devoted to study of the contact problem for a punch with a complex shape and a base with a coating consisting of nonuniform layers of variable thickness. Such a foundations are often found in practice. Coating layers in them can play a role, for example, heat or electric insulators. Such layers can be used as protection against mechanical stress on the main structure. Mathematical model of the problem is constructed. It is a mixed integral equation containing functions that describe the properties and thicknesses of the layers, as well as the shapes of the contacting bodies, and additional integral conditions. Analytical solution of the problem is presented for one of the formulation options. In the resulting solution, the functions associated with the properties and forms of bodies are distinguished by separate terms. This allows one to perform high-quality calculations and analysis of the behavior of the punch on the layer, even if these functions are rapidly changing.