Propelling boats with sails has been going on for thousands of years. In the old days the sailors had very little control and most sailing was done downwind or with the wind pushing on the sails in order to move the boat.
More recent technologies have made sailing, especially racing, much more controlled and allows boats to sail closer and closer to the wind.
As a rule of thumb, a recreational vessel will be able to sail only in areas that are at least 45 degrees off the wind on either side of the direction from which the wind is blowing. This is called the "no go zone" and to get to a location upwind you have to do a maneuver called a tack. This back-and-forth maneuver with the bow going through the wind and the sails being transferred from one side to the other eventually gets you to your upwind mark.