I would not edit a unit file under /lib/systemd/system. The next package update can overwrite it, and then your change is gone without a word.
Use a drop-in instead:
sudo systemctl edit nginx
This opens an empty editor. Whatever you write is saved as override.conf in /etc/systemd/system/nginx.service.d/, and systemd reloads its configuration when you save. For example:
[Service]
Restart=on-failure
RestartSec=5
Check the merged result with systemctl cat nginx, which shows the original unit and every drop-in below it.
The caveat: settings that can appear several times, like ExecStart=, are added to the existing ones. To replace them, first write an empty ExecStart= line and then your own. Running services need a restart before they pick up the change.
I like this because it keeps my changes small and visible. Three lines in a drop-in file are easier to review later than a modified copy of the whole unit. And if I want to go back, I delete one file, or run systemctl revert nginx, and the service is back to what the package shipped.
Further reading: systemctl man page, systemd.unit man page, On this site: journalctl –vacuum-size caps how much log space you keep, On this site: systemctl list-timers is cron's answer inside systemd