Why do propeller airplanes mostly have their propellers in front (of the fuselage or wings) while ships and boats mostly have them at the back?
I realize that there are aircraft with pusher configurations but they are relatively rare.
There are quite a lot of reasons for this, but it's a complicated design environment, and that's why it's not always the case.
Seals and cooling
The inside of a plane's wings is the same fluid as the air around it, but the inside of a boat's hull is a different phase than the water outside. Basically you can never have a rotating shaft over a pressure difference that doesn't permit some fluid through, around the shaft. There are ways to mask this, so that no one ever sees water leaking into the hull. For instance, you can have an intermediate stage between the hull and the water where air is pumped into a higher pressure cavity. Then it's possible that the seal can bubble with air passing out into the water.
Whichever design the ship maker uses you can't change the physical fact that you'll have some fluid flow through the prop seals, be that air or water. This presents a good reason to have the prop on the back of boats and the front of planes. Pressure is higher at the front because of the kinetic pressure of the fluid, and lower at the back for the reverse reason. By putting the prop of a boat in the back you reduce the pressure difference that the seals have to deal with. The plane has no such concern, and might prefer more air pressure and flow around its engines for cooling. In fact, Wikipedia seems to agree with the cooling point for plane engines.
In pusher configuration, the propeller does not contribute airflow over the engine or radiator. Some aviation engines have experienced cooling problems when used as pushers. To counter this, auxiliary fans may be installed, adding additional weight.
A moving boat or plane has an aerodynamic center of pressure. If this point is behind the point of thrust, then it's a more stable setup and if it's in front then it's a less stable setup. It's likely not a problem either way because there are other dynamical factors that make it stable, or you have a pilot that acts as an active control system.
Nonetheless, planes worry about stability a lot more than boats.
As others have pointed out, boats logically don't want the prop in the front because you're more likely to hit something (like a sandbar) with the front of the boat, and you don't want to shred things. This quite possibly dwarfs the basic physical considerations.
In fact, as I was thinking about cavitation concerns, it seems clear that the back of the boat isn't the ideal place. Directly under the hull would be superior. But this a) doesn't give a direct shaft line to the engine and b) it could make the prop hit the ground or a whale. For this case, it's clear that the operational safety concerns are much more pressing than a little bit more performance.
Well the issue is relatively simple.
With the boat, all that is required is to propel the boat forward, and that is best achieved by accelerating a mass of water in a direction opposite to the direction of boat travel. That is best achieved by expelling the accelerated water into as unrestricted a space as possible; which clearly is behind the boat. With the propeller in front, the accelerated water has to move around the bow of the boat, so part of the energy is wasted moving the water sideways, away from the hull, and generating no net thrust since the two sides cancel out, so only the component of the velocity along the path of travel is useful in driving the boat.
With an aero-plane, there is an additional interest, namely increasing the lift of the wing, specially at low forward speeds such as at take off and landing. So having the propeller in front, (specially with twins) even at zero speed, the air flow over the wings, provides significant lift, reducing the necessary take off speed, and the possible landing speed. The plane propeller, even with a single engine, has a larger diameter, than the profile of the fuselage, and the propeller is designed so that most of the air movement is generated near the tips, rather than at the hub, so the energy lost to the fuselage drag is minimal.
Pusher propeller planes, or push-pull duals, are quite popular when used on primitive air strips, that may have loose stones on them, so the prop wash is not kicking up stones into the fuselage.
A boat is most efficient when it is riding on a plane. This happens when the boat reaches a certain speed and is essentially lifted out of the water. This can not happen if the propeller were located on the front of the boat. Look up a boat with a hydrofoil and you can see how it works.
I don't know much about this, but this is my view
In ships and boat's we have propellers at back because water is relatively too much denser the air so if propeller's were fit in front of ship or the boat the turbulence created bu the propeller in the water would create too much drag with the ships hull and make it difficult for the ship to move. The drag in case of ship and water is too high that is why ships are fitted with the baw in front of them to avoid as much drag as possible, whereas in case of plane the propeller are fitted on the wing or in the front of the plane that is obvious as the drag due to air turbulence is not much it is noticeable, however since air is not so dense so the drag due to it's turbulence is not so high so high which can be compensated. But planes have propeller's at back also like this one
For an aeroplane while flying its stability is very important.the heaviest part in a plane are its engines.to get better stability the engines have to be placed in the right place considering its weight distribution of fuel tanks (wings) and cargoes and seating.that is why it is not just in the front it is placed in the right place as its center of mass.few planes even have 3rd engine placed just front of its tail to equalise the weight distribution.but for a ship it pretty much stable in water as it floats.the engines are used for propulsion thrust.its turbulant flow behind engines creates a drag causing it to reduce its speed if it were in the front.also it makes ships to steer the ship easier if its at the rear instead of middle or front with the help of tail or diverter.
A boat has the prop in the stern (rear) for a few reasons: 1. The prop is protected by the keel from running aground, colliding with other ships, and hitting objects in the water such as logs, reefs, sandbars, etc. 2. Engines produce exhaust and it is more convenient to the occupants of a boat if the exhaust isn't blowing across the deck and into the faces of the occupants when cruising (thus the engines are typically placed in the stern/rear of the ship). 3. There will be a loss of efficiency with an increase in the number of turns in the shaft between the prop and the engine. If the engine is placed in the back of the ship, it is more efficient to have the shaft going straight out the back rather than turning forward and less expensive than running the shaft all the way to the front of the ship (or the exhaust pipe all the way to the back). 4. The prop crates turbulence against the hull which increases drag. 5. The front/bow of ships are designed to lift out of the water more than the stern. 6. Placing the prop in front will increase the water pressure on the seals around the prop which would require more maintenance and replacement than in a rear mounted position where the water pressure is less due to the water pulling away from the ship rather than being compressed in front of the ship (those seals are waterproof in equilibrium but tend to leak which is partly why boats have bilge pumps to drain the water that has leaked in out of the ship).
This ship uses a more efficient design of a forward facing prop (like that found on aircraft) but the props are still in the stern/back of the ship and thus the props are back there too. However, these are forward facing (still partially protected by the keep of the ship) and are more efficient than the rear facing design because the props cut through the fluid medium before the water is disrupted by the flow around the pods containing the drive shaft. This creates a more lanier flow than the rear facing design. https://i.imgur.com/UTRFAGP.jpg
P.S. In response to an earlier answer, boats are designed to float but they have to be balanced just like aircraft to float correctly in the water. Too much weight to one side or another or up front or in back can cause a ship to become unstable and capsize. Thus the engine placement in back is designed to counter the interior and cargo weight of the rest of the ship. Just like a Cessna 172 Skyhawk had the engine and prop forward of the wings and the rest of the plane behind the wings.