This guide will cover how to completely uninstall the Nginx web server (including its dependencies, modules, configuration files and logs) on Debian/Ubuntu-based Linux distros (e.g. Linux Mint, Pop!_OS, Elementary OS). It's useful when you're trying to reinstall a clean Nginx server.
In case the Nginx server is still running, let's stop the Nginx service (
$ sudo systemctl stop nginx
In this step, we'll uninstall Nginx and its related packages from our system.
Purge the main Nginx packages:
$ sudo apt purge nginx*
Remove the unused dependencies with
$ sudo apt autoremove
Although Nginx is now uninstalled, there are still some files generated by Nginx left to clean.
Remove the configuration files in
$ sudo rm -rf /etc/nginx
Remove the logs in
$ sudo rm -rf /var/log/nginx