How to Disable a Site in Nginx: Simple Steps
To disable a site in
nginx, remove or unlink its configuration file from the sites-enabled directory and reload nginx with sudo systemctl reload nginx. This stops nginx from serving that site without deleting its configuration permanently.Syntax
In Nginx, sites are enabled by placing configuration files in the sites-enabled directory, usually linked from sites-available. To disable a site, you remove or unlink its file from sites-enabled and reload Nginx.
sudo rm /etc/nginx/sites-enabled/example.com: Removes the enabled site link.sudo systemctl reload nginx: Reloads Nginx to apply changes without downtime.
bash
sudo rm /etc/nginx/sites-enabled/example.com sudo systemctl reload nginx
Example
This example shows how to disable a site named example.com by removing its symbolic link from sites-enabled and reloading Nginx to stop serving it.
bash
sudo rm /etc/nginx/sites-enabled/example.com sudo systemctl reload nginx
Output
No output if successful; Nginx reloads without errors.
Common Pitfalls
Common mistakes when disabling a site include:
- Deleting the configuration file from
sites-availableinstead of just unlinking fromsites-enabled, which removes the site permanently. - Forgetting to reload Nginx after disabling the site, so changes do not take effect.
- Using
systemctl restart nginxunnecessarily, which causes a brief downtime instead of a smooth reload.
bash
Wrong way: sudo rm /etc/nginx/sites-available/example.com sudo systemctl reload nginx Right way: sudo rm /etc/nginx/sites-enabled/example.com sudo systemctl reload nginx
Quick Reference
Summary tips to disable a site in Nginx:
- Remove or unlink the site config from
sites-enabled. - Do not delete the config from
sites-availableunless you want to remove it permanently. - Reload Nginx with
sudo systemctl reload nginxto apply changes smoothly.
Key Takeaways
Disable a site by removing its link from /etc/nginx/sites-enabled.
Always reload Nginx after disabling a site to apply changes.
Do not delete the site config from sites-available unless permanent removal is intended.
Use reload instead of restart to avoid downtime.
Check Nginx configuration syntax with sudo nginx -t before reloading.