What board or boards; what wind; planing or sub-planing; sailor skill level? There are different techniques for different situations and equipment.
From your post, I am guessing you are on a "short" board in planing conditions. If this is the case, it's pretty simple - You need plenty of power (speed) and a medium to large fin, then sink the leeward rail and "ride the fin" with most of your weight on the back foot. Wide boards don't rail over as much, but the concept still applies. If it doesn't work, you need either more wind and or a larger sail. A flatter sail is more efficient upwind, assuming you have plenty of power (large enough sail). A tighter leech will add a little more power, but will be un-forgiving in the wind gusts (backwinded and "splat").
If the power isn't quite stong enough or you hit a hole, hanging in your harness (putting weight on the mast foot) will help keep the board railed over in the right postion. If this won't keep you on the same line, then you have to bear off and re-gain speed and then head up again.
Formula 160; iSonic 111; HiFly Move 105; Tiga 263; '85 Mistral Superlight.
Maui Sails TR 11.0; 9.2; 8.4; 7.6; 6.6; Maui Sails Switch 6.0; 5.2; Maui Sails Global 4.5; 4.0.