Feynman's functional formulation of statistical mechanics is used to study general-relativistic quantum field theories at finite temperature. The techniques are then applied to gauge theories. The partition function Tr e -β H is discovered to be a gauge-dependent quantity which is meaningless in most gauges. Instead; we define a physically meaningful partition function which is gauge-invariant and only equal to Tr e -β H in certain "physical" gauges. Feynman rules for this partition function and for finite-temperature Green's functions are derived for a general gauge.