Why Doesn't The Boat Drift Sideways?
Lift
Explaining how a boat sails downwind is fairly straight forward, you open the sails as far as possible and the wind pushes the sails, moving the boat along...simple.
Explaining how a boat sails upwind is a little harder, after all, you're sailing against the only apparent force (the wind) that you have to push you along. However, the force of the wind on a sail works exactly in the same way as a wing on an aeroplane and blades on a wind turbine, air moves across the surface of the wing / blade and creates a force called lift. Lift on a sail is created by the following:
Air travelling around the outside of the curve of the sail takes a longer path than the air around the inside of the sail. This longer path means the air travels faster around the curve of the path, causing a lower pressure than the air surrounding it.
Inside of the sail, the air has a shorter path to travel so travels at a much lower speed and has a lot more pressure.
This difference in pressure between the inside of the sail and the outside of the sail causes lift, a force that helps push the boat through the water.
Keel / Centreboard
Lift isn't the only force required for a boat to travel upwind, keels/centreboards prevent the boat from being pushed sideways through the water by the wind. The force applied by the water on the keel acts in the opposite direction to the force of the wind, these 2 forces squeeze the boat, pushing it forwards through the water, similar to when you squeeze a bar of soap in your hands.