A variational approach to the shock structure problem is proposed. The set of governing equations, consisted of n first-order ordinary differential equations accompanied with 2n boundary conditions at ±∞, is put into variational form by means of least-squares method. The corresponding variational principle is adjusted for application of Ritz method. This direct method is used for construction of approximate analytical solutions to the shock structure problem and derivation of the estimates for the shock thickness. General procedure is applied to the study of Burgers' equation and equations of gas dynamics.