← All articles

How to restart Nginx or Apache safely on a production server

Never blind-restart a web server on production. Test config first, prefer reload over restart, and confirm the upstream app is healthy before touching the proxy.

On production, restarting Nginx or Apache without testing config is how you cause downtime. Safe order: verify upstream app → test config → reload → confirm from outside.

Nginx (Ubuntu / Debian)

sudo nginx -t
sudo systemctl reload nginx
sudo systemctl status nginx
curl -I https://yourdomain.com

Use restart only if reload does not apply changes or the master process is hung:

sudo systemctl restart nginx

Apache

sudo apache2ctl configtest
sudo systemctl reload apache2
sudo systemctl status apache2

On RHEL/CentOS: httpd instead of apache2.

Before you touch the proxy

  1. Backend healthy? systemctl status on php-fpm, gunicorn, Node, etc.
  2. Backup config sudo cp /etc/nginx/sites-enabled/site /etc/nginx/sites-enabled/site.bak
  3. Low-traffic window if you must restart (not reload)
  4. Have rollback — keep the last working config one copy away

Reload vs restart

ActionDowntime riskWhen
reloadLowConfig change, TLS cert renewal
restartHigherStuck workers, upgrade, rare corruption

After certbot

Certbot often reloads Nginx for you. If not: sudo nginx -t && sudo systemctl reload nginx.

AI-assisted restarts

If you are unsure which service to restart, an AI DevOps Copilot can walk through checks first. Ohuriya AI shows every command—nginx -t, systemctl status, curl—and runs nothing until you approve. Learn more · 502 troubleshooting

Quick answers

Should I restart or reload Nginx on production?

Prefer reload: sudo nginx -t && sudo systemctl reload nginx. Reload applies config without dropping all connections. Full restart is for when the master process is stuck.

How do I restart Apache safely?

Run sudo apachectl configtest (or apache2ctl -t), then sudo systemctl reload apache2. Fix config errors before reload—bad syntax takes the site down.

What if restart fails?

Do not panic-restart again. Read journalctl -u nginx -n 50, fix the config error, nginx -t until clean, then reload. Keep the previous config backed up.