How far away should the vertical stabilizer be from the leading edge of the main wings?
The reference point is not the leading edge but the center of gravity (CG), which is a little further back.
The ability of a fin to generate a yawing moment is proportional to both its area $A$ and its distance $l$ behind the CG. It is therefore also proportional to their product. This has units of $L^3$ so it is known as the tail volume $V$:
$V = A.l$
So the nearer the fin is to the CG, the larger it needs to be. On the other hand, the smaller a fin is, the farther back you have to build it out.
In practice everything in front of the fin, usually the fuselage and/or wing, can affect the airflow over it and reduce its effectiveness. This is especially significant at high angles of attack, such as when taking off or landing, and extra height is often added for this reason.
However a very tall fin also exerts a strong rolling moment, which can cause awkward stability problems such as Dutch roll.
At supersonic speeds, the pressure above the rear of the wing and fuselage falls, reducing the effectiveness of the fin. However the pressure under them increases, so underside strakes become very effective for their size.
Placing a very large fin above and close to the main wing is about the worst thing you can possibly do.
The optimal distance back depends on many design factors but is usually around a half- to three-quarter span, though it can be further for supersonic aircraft.