NGINX is known for being one of the fastest web servers and is considered one of the best open-source load balancers. There might be scenarios when you are required to reinstall or completely remove NGINX from your system.
We will guide you through the complete process of how you can uninstall NGINX from Ubuntu 22.04 or later with backing up configuration files and the reinstallation process.
- What is NGINX and What Makes it Special?
- Key Features of NGINX:
- Uninstalling NGINX from Ubuntu 22.04
- Backing up and Deleting Configuration Files
- Reinstalling NGINX
- Frequently asked questions related to NGINX
What is NGINX and What Makes it Special?
NGINX is pronounced as “engine-x” widely known for its superfast web servers and being open source adds up a sweet layer of security over it. After getting success as web servers, they have also started services such as reverse proxy, HTTP cache, and load balancers.
It is used by some of the biggest tech giants around the world including IBM, Google, Adobe, LinkedIn, Cisco, Facebook, Twitter, Apple, and many many more.
The key advantage of NGINX is that it uses less memory with high concurrency. Rather than making a new process for each request, it handles multiple requests in a single thread for better efficiency.
Key Features of NGINX:
- Reverse proxy
- Advancements such as IPv6
- Load balancing
- FastCGI support
Uninstalling NGINX from Ubuntu 22.04
For uninstalling NGINX without any issues, we are required to check the status of NGINX. The reason behind doing this is that if any service is active and we will try to remove it, you will get errors. To check the status of NGINX uses the following command:
sudo systemctl status nginx
As you can see it’s running in the background. Pass the following command to stop NGINX:
sudo systemctl stop nginx
Now, let’s check the status of NGINX again
sudo systemctl status nginx
As you can see, NGINX is not running. We can proceed further in our uninstallation process.
Backing up and Deleting Configuration Files
we are going to purge NGINX to remove dependencies and old configuration files but if you think some important files should be kept alive, you will find files at /etc/nginx and your site content will be at /var/www.
For backing up, use the following commands:
sudo mv /etc/nginx /etc/nginx_bk
What this command will do is rename the file stored at /etc/nginx to the same location with the new name nginx_bk (bk indicates backup)
sudo mv /var/www /var/www_bk
as same as above, we have renamed site data stored at /var/www to www_bk
if you don’t need those files anymore and want to remove them completely, use the following command:
sudo rm -r /etc/nginx /var/www
We have deleted both files using a single command.
After having a proper backup, we are ready to remove NGINX from Ubuntu System. The reason why we are going with purge is we want to remove all the previous configuration and dependencies. Use the following command to purge NGINX from your system:
sudo apt purge nginx
sudo apt purge nginx-common
Clearing up Leftovers
This is the last step where we are going to remove unnecessary files from our system. Use the following commands:
sudo apt autoremove
As you can see, unnecessary files have been removed and freed 2,333 kB of space.
sudo apt autoclean
After clearing all the old mess, we are ready with a clean system for the fresh installation of NGINX. When you reinstall NGINX, it will generate new files at /etc/nginx.
Use the following commands to install NGINX
sudo apt install nginx
You have a fresh copy of NGINX installed with the default configuration.
Where is nginx conf located?
You can find every NGINX configuration file located at /etc/nginx/ directory. If you want to know the exact location of the main configuration file, it is located at /etc/nginx/nginx.conf.
How do I stop and start nginx?
If you are using Ubuntu 16.04 LTS or above, you can use:
sudo systemctl restart nginx (for restarting)
if you are using an older version of Ubuntu use the following command to restart:
sudo /etc/init.d/nginx restart
- Uninstall MySQL in Ubuntu
- Install Tor Browser in Ubuntu
- Shell user theme extension not enabled fixed
NGINX is one of the fastest web server providers and gets you great performance. It generally does not cause any problems but if you still get any, you can easily backup your data and uninstall NGINX from Ubuntu 22.04 and reinstall it again.