It is impossible for a sailboat to sail directly into the wind. This is because the wind exerts a forward force on the sails of the boat, which tends to push the boat backwards or make it lose speed. In order to move forward, a sailboat must generate lift by angling its sails in such a way as to create a force that is directed forward and upwards. However, when the wind is coming directly from ahead, it is difficult to impossible enough lift (if any at all) to overcome the force of the wind and move the boat forward. By carefully adjusting the angle of the sails and the position of the keel or centerboard, a skilled sailor can sail a boat in a wide range of directions, including close to the direction of the wind.
How to sail upwind (kind of)
The most efficient way for a sailboat to travel upwind is to use a combination of the sails and the keel or centerboard to generate lift and counteract the force of the wind. The sails are angled in such a way as to generate lift, which propels the boat forward. The keel or centerboard, which is a long fin-like structure that extends downward from the hull of the boat, helps to prevent the boat from being blown sideways by the wind. By carefully adjusting the angle of the sails and the position of the keel or centerboard, a skilled sailor can sail a boat close to the direction of the wind, even if it is coming from directly ahead. This is known as tacking, and it allows the boat to make progress upwind without losing much speed or control.
Although a sailboat can never sail into the wind, it can sail close to the wind (about 45 degrees in either direction), and this is used to travel in the general direction of the wind. If a zig-zag pattern is used, the sailboat will eventually be able to travel upwind.
This zig-zag pattern is actually how most competitive sailboat races work. An upwind/downwind course is a staple among the racing community.