With an afterburning engine you can't bury the engine forward and use a long duct to the exhaust nozzle because the length of the afterburner chamber is limited, and the afterburner nozzle has to be the last thing the supersonic air passes through. If there is no afterburner, the exhaust duct can be fairly long with a simple convergent nozzle at the end (like an F-86, which has its engine midships with a long exhaust duct).
The nozzle on an afterburning engine does double duty. Burner off, it's a normal taipipe with simple convergent nozzle tip. Burner on, the nozzle morphs into a venturi shape (a convergent/divergent duct, like a rocket exhaust) to manage the supersonic flow created by the afterburner. So the nozzle has to be at the back, and the engine has to be close to the nozzle, how close determined by the length of the afterburner chamber.
You could put an afterburning engine amidships, but you'd then have to have a high tail to clear the exhaust nozzle which now has to be ahead of the tail (like an F-101 Voodoo). But if you want to also use the nozzles for steering, you want them as aft as possible to get the most pitch authority. So the engines on the F-22 end up at the tail and the only airplanes you see with fully buried engines and longish shrouded exhaust ducts (F-117 and B-2) are subsonic a/c without afterburners.