Enter your email address below and subscribe to our newsletter

How to Uninstall NGINX Ubuntu 22.04

Share your love

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?

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:

  1. Reverse proxy
  2. Advancements such as IPv6
  3. Load balancing
  4. FastCGI support
  5. Websockets

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 

1. 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 

2. sudo systemctl stop nginx

Now, let’s check the status of NGINX again

 sudo systemctl status nginx 

3. 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 

4. sudo mv nginx

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 

5. sudo mv www

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 

6. sudo rm -r

We have deleted both files using a single command.

Purging NGINX

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 

7. sudo apt purge nginx

 sudo apt purge nginx-common 

7. 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.

8. sudo apt autoremove

 sudo apt autoclean 

9. sudo apt autoclean

Reinstalling NGINX

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 

0. Reinstallation

You have a fresh copy of NGINX installed with the default configuration.

Frequently asked questions related to NGINX

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

Related Posts:

Conclusion

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.

Share your love
Sagar Sharma
Sagar Sharma

Sagar always uses Linux to its core and loves to write the technical side of system administration! While he's not writing for GeniusGeeks, you can find him writing for core linux blogs like IT'SFOSS.com and LinuxHandBook.com

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!