Certainly! Here’s the complete, revised set of steps to fully uninstall and reinstall Nginx on Debian 12, ensuring all configurations are reset:
Step 1: Stop and Disable Nginx
Stop the Nginx service to ensure it’s not running:
1 |
sudo systemctl stop nginx |
Disable Nginx so it won’t start on boot:
1 |
sudo systemctl disable nginx |
Step 2: Uninstall Nginx with Purge
Use the --purge
option to remove Nginx along with its configuration files:
1 |
sudo apt remove --purge nginx nginx-common nginx-full -y |
Step 3: Remove Residual Files (Optional)
If there are any remaining files or directories related to Nginx, you can delete them manually:
1 |
sudo rm -rf /etc/nginx /var/log/nginx /var/www/html |
Step 4: Clean Up Unused Dependencies
Remove any dependencies that were installed with Nginx and are no longer needed:
1 |
sudo apt autoremove -y |
Step 5: Reinstall Nginx
Now, reinstall Nginx. This will reinstall the package along with the default configuration files:
1 |
sudo apt install nginx -y |
Step 6: Verify Configuration File Exists
After reinstalling, check if the main configuration file, /etc/nginx/nginx.conf
, is in place:
1 |
ls /etc/nginx/nginx.conf |
Step 7: Test Nginx Configuration
Before starting Nginx, confirm that the configuration file is valid:
1 |
sudo nginx -t |
Step 8: Start and Enable Nginx
If the configuration test passes, start the Nginx service:
1 |
sudo systemctl start nginx |
Enable Nginx to start automatically on system boot:
1 |
sudo systemctl enable nginx |
Step 9: Verify Nginx is Running
You can check the status to confirm Nginx is running without errors:
1 |
sudo systemctl status nginx |
Following these steps will ensure a clean removal and fresh installation of Nginx, with the default configuration reset on Debian 12.