The tail of a comet is technically called a coma and is the vapor of the outer ice layer, which evaporates with heating as the comet approaches the Sun. The solar wind causes the coma to always point away from the Sun. The tail glows due to the fluorescence of these gases.
The comet also has other less pronounced tails formed from dust. Their direction is not affected in any way by the solar wind, and therefore their direction is the same as the direction of movement of the comment. We see these tails due to the reflection of light from the surface of dust particles.