After having read aeroalias' picture collection, I feel an urge to chime in.
Longitudinal position
The main reason to place them ahead of the wing is flutter suppression. Flutter is an oscillation caused by the interaction of elastic and aerodynamic forces. In case of the wing, it is an up-down bending motion. Since air takes its time to flow over the wing, at a certain airspeed the air pressure change on the wing is so much out of phase with the motion that it amplifies the elastic motion of the wing. By placing the center of gravity of the aircraft part ahead of its elastic axis, flutter can be suppressed. This is true of flaps (where a mass balance is added ahead of the hinge line) as of full wings (where engines take the part of the mass balance).
Imagine the wing bending up, and now add the inertial forces of an engine connected to this wing and also moving up. If it is placed ahead of the elastic axis, it will induce a torsion moment into the wing, such that the local angle of attack is reduced, which in turn will reduce lift and the forces which cause the wing to bend upwards. The same happens in opposite direction when the wing bends downwards. Since the biggest thickness of the wing is in its forward section (which shifts the elastic axis forward) and the heavy flap mechanism is in its rear section (which shifts the local center of gravity back), a wing without an engine mounted forward of it needs a much heavier structure or less heavy, but otherwise unproductive, balance weights.
Placing the engine ahead of the wing brings some more benefits:
Why engines are not placed on top of the wing is discussed in esta resposta.
Lateral position
In two- and three-engined jets you put them at the wing station where the inner wing ends. The main reasons are:
- There is a major rib anyway to support the wing's skin, so the structure for attaching an engine is easier to add.
- There is a gap between inner and outer flaps (at least in Boeing designs), so the engine blast will not hit the flaps.
- They are still relatively close to the center of the airplane to not require an excessively large vertical tail to cancel the yawing moment in single-engine flight.
Boeing 737 bottom view (picture by Adrian Pingstone). The inner wing section has an unswept trailing edge while the outer wing has less taper and a swept trailing edge. The engines are exactly where both meet.
Aircraft like the DC-8 had their inner engines at the wing rib which supported the inner flap tracks of the outer Fowler flap, because they had no gap between inner and outer flaps. On the DC-10, Douglas placed the wing engines at the break between inner and outer wing, however.
In four-engined jets the inner engines are placed like those on two-engined jets, while the outer engines are placed at the end (or slightly outside) of the outer Fowler flaps, about midway between the inner engine and the wing tip. Note that again a rib is needed where the aileron cutout starts - this rib doubles as the engine mount. There the engines can contribute a lot to bending relief, and since a single engine contributes only 25% of the total thrust, the yawing moment of the outer engine in the engine-out case is roughly equal to that of a single engine of a two-engined jet.
Airbus A340 bottom view (picture by Adrian Pingstone).
Why it is better to separate the engines and spread them out over the wing instead of collecting them in a single nacelle is explained in esta resposta.
In some cases, the engine location is dictated by other requirements. On the Antonov An-70 the inner engines need to be far enough out to allow to drop paratroopers from the front door, for example.