To rein in a leaky service quickly I set a limit at runtime and check it, before I write anything to a unit file.
sudo systemctl set-property --runtime nginx.service MemoryMax=500M CPUQuota=50%
systemctl show nginx.service -p MemoryMax -p CPUQuotaPerSecUSec
MemoryMax= is a hard cgroup limit. When the service exceeds it the kernel reclaims memory and may kill processes inside it. CPUQuota=50% caps the service at half of one core. --runtime keeps the change until reboot, and without it systemd writes a persistent drop-in under /etc/systemd/system.control. The limits need cgroup v2 on current Debian and Ubuntu releases.
Further reading: systemd.resource-control manual page