Chapter 8: Configuring Nginx and Apache
8.9 The safe change workflow
Dhyan do, this is the habit that separates a professional from a beginner:
sudo cp site.conf site.conf.bak # 1. backup (name must not end in .conf)
sudo nano /etc/nginx/conf.d/site.conf # 2. edit
sudo nginx -t # 3. test syntax
sudo service nginx reload # 4. reload (no downtime)
curl -I -H "Host: example.com" http://localhost # 5. verify from inside
sudo tail -n 20 /var/log/nginx/error.log # 6. check the log
For Apache, replace step 3 with sudo apachectl configtest (Ubuntu: sudo apache2ctl configtest) and step 4 with sudo service httpd reload (Ubuntu: sudo service apache2 reload). If something breaks, copy the .bak back, test and reload. You'll be online again in seconds.
reload vs restart
reload re-reads the configuration while keeping existing connections, and refuses to apply a broken config. restart stops everything first. Use restart only when a module or port change needs it, or when reload doesn't pick up a change.