How to Uninstall NGINX in Centos

NGINX is a popular web server that is also used as load balancer and reverse proxy. But sometimes you may need to remove NGINX from your system, due to performance issues or because you want to use another web server. In this article we will look at how to uninstall NGINX in CentOS. You can use these steps to uninstall NGINX from RHEL & Fedora Linux as well.
How to Uninstall NGINX in Centos
Here are the steps to uninstall NGINX in CentOS. Please note, you will need a user with root privileges to execute the following commands.
1. Stop NGINX Server & Remove Auto Start
Open terminal and run the following commands to stop NGINX server and remove its auto start script.
# sudo systemctl stop nginx.service # sudo systemctl disable nginx.service
2. Remove NGINX user
Run the following command to remove nginx user and its directory.
# sudo userdel -r nginx
3. Delete NGINX
Run the following commands to delete NGINX installation folder and related directories.
# sudo rm -rf /etc/nginx # sudo rm -rf /var/log/nginx # sudo rm -rf /var/cache/nginx/
4. Remove NGINX Service
Finally, run the following commands to remove NGINX service from your system.
# sudo rm -rf /usr/lib/systemd/system/nginx.service
That’s it. NGINX will be completely removed from CentOS/RHEL/Fedora Linux.
How to Remove / Uninstall Nginx on CentOS 7 / RHEL 7 / Oracle Linux 7
Nginx is a popular web server and reverse proxy server, known for its high performance and low resource consumption. However, if you have decided to switch to another web server or no longer need Nginx on your CentOS 7, RHEL 7, or Oracle Linux 7 system, you may want to uninstall it.
In this guide, we will demonstrate how to remove or uninstall Nginx on CentOS 7, RHEL 7, or Oracle Linux 7 using the command line. Following these steps, you will be able to remove the Nginx package and its associated configuration files from your system.
See also How to Pass Clients/Visitors IP Through Varnish to Nginx
Step 1: Stop the Nginx service
Before uninstalling Nginx, ensure that the service is stopped:
sudo systemctl stop nginx
Step 2: Remove Nginx package
Now, remove the Nginx package using the yum package manager:
sudo yum remove nginx -y
This command will uninstall the Nginx package and its dependencies that are no longer required.
Step 3: Remove Nginx configuration files and logs (optional)
If you wish to remove the Nginx configuration files, logs, and other associated files, you can delete the following directories:
sudo rm -rf /etc/nginx sudo rm -rf /var/log/nginx sudo rm -rf /var/cache/nginx
Please note that this step is optional and should be performed with caution, as it will permanently delete the files and directories.
See also How to Install VMware Tools on Red Hat Enterprise Linux 6.2 (RHEL 6.2)
Programs Mentioned:
- Nginx – A high-performance web server and reverse proxy server used to serve web content and proxy requests efficiently.
- systemctl – A command-line utility used to control the systemd system and service manager, allowing you to manage services and other system components.
- yum – The default package manager for CentOS 7, RHEL 7, and Oracle Linux 7, used to install, update, and remove packages on the system.
Conclusion
By following this guide, you have successfully uninstalled Nginx on CentOS 7, RHEL 7, or Oracle Linux 7. The Nginx package, its configuration files, and logs have been removed from your system, allowing you to install another web server or repurpose the system as needed.
See also How to Install and Use Traceroute in Linux RHEL 6/7, CentOS 6/7, Oracle Linux 6/7
If you have any questions, comments, or suggestions for improvements, please feel free to share your thoughts. Your feedback is crucial in helping us provide the most accurate and useful information possible.
Dimitri Nek
Dimitri is a Linux-wielding geek from Newport Beach and a server optimization guru with over 20 years of experience taming web hosting beasts. Equipped with an arsenal of programming languages and an insatiable thirst for knowledge, Dimitri conquers website challenges and scales hosting mountains with unmatched expertise. His vast knowledge of industry-leading hosting providers allows him to make well-informed recommendations tailored to each client’s unique needs.
How to Uninstall Nginx Completely
In this article, we’ll be going over the steps to follow when uninstalling the NGINX web server. We’ll cover both Debian and RPM-based systems.
2. Uninstalling NGINX in Debian Systems
Due to different reasons, we might decide to uninstall NGINX. This might result from wrong configurations or us just wanting it out of our systems.
To uninstall NGINX in our Debian-based system, we have two options to choose from. To begin with, we can either use the apt remove command or choose the apt purge command. Before we look at either of these commands, let’s check the state of our NGINX server. To check the status, we’ll use the systemctl status command since it works for both the Debian- and RPM-based systems and any other Linux system that uses systemd:
$ sudo systemctl status nginx.service ○ nginx.service - A high performance web server and a reverse proxy> Loaded: loaded (/lib/systemd/system/nginx.service; disabled; v> Active: inactive (dead)
This command shows us if the server is active (running) or if it’s inactive (dead/ not running). Now, let’s go ahead and look at how to uninstall it.
2.1. Remove NGINX
We can use apt remove to uninstall NGINX:
$ sudo apt remove nginx
This removes NGINX from the system but leaves the configuration files behind. In other words, the site configuration files found in the /etc/nginx folder are left and aren’t removed. The site files placed in the /var/www won’t be wiped out during this process. Using apt remove for the job is only beneficial if we plan to reinstall NGINX in the future.
When issuing this command, we can further add separate NGINX packages that we’d want to be removed at the same time. For example. we can run:
$ sudo apt remove nginx nginx-commons
When we check the status of the server now, we find out that it has been masked:
$ sudo systemctl status nginx.service ○ nginx.service Loaded: masked (Reason: Unit nginx.service is masked.) Active: inactive (dead)
2.2. Purge Nginx
Apart from the remove command, we can also use purge to remove NGINX:
$ sudo apt purge nginx
The apt purge command completely removes NGINX from our system. It will uninstall the NGINX server and delete the /etc/nginx folder with all its contents. This command also deletes all the configuration files and settings associated with the NGINX server.
Using apt purge to uninstall NGINX is the best option if we don’t expect to use NGINX in the near future. It’s also the preferred way if we want to perform a clean re-installation of the same version of NGINX or a later one.
After running purge, if we check the status, we won’t find the nginx.service unit, thus confirming that the server has been deleted completely:
$ sudo systemctl status nginx.service Unit nginx.service could not be found.
After uninstalling NGINX using the purge command, we have to remove all the remaining dependencies that were used by NGINX but are not required anymore:
$ sudo apt-get autoremove
2.3. Nginx Failed to Remove
We need to note that, in some occurrences, running the above commands may not wipe out NGINX completely, and upon restart, NGINX may still be running. This may be caused by us removing the wrong variant of the installed NGINX server.
NGINX has different flavors available. These flavors are nginx-core, nginx-full, nginx-light, nginx-extras, nginx-naxsi, and nginx-common (NGINX is a meta package). In such a precedent, we can run:
$ sudo apt-get remove --purge nginx*
This will remove anything installed that is related to NGINX. It’ll also remove the configuration files, and additionally, it will list packages available in repositories that matched the regex “nginx*” (these packages are just listed and aren’t installed). If we check the status, it will give us similar output to that of the purge command.
Again, if the autoremove command doesn’t purge auto-removable packages by default, then we can use:
$ sudo apt-get autoremove --purge
3. Uninstalling NGINX in RPM Systems
For RPM-based distros like CentOS7, RHEL7, and Fedora, if we want to remove NGINX, we go through a different set of steps. First, we have to stop and disable the NGINX service from running:
$ sudo systemctl stop nginx.service $ sudo systemctl disable nginx.service
Secondly, we remove the auto-start from NGINX:
$ sudo chkconfig nginx off
Following, we proceed to remove all NGINX files, including binary files, configuration files, and even jpg files:
$ sudo rm -rf /etc/nginx $ sudo rm -rf /etc/init.d/nginx $ sudo rm -rf /var/log/nginx $ sudo rm -rf /var/cache/nginx/ $ sudo rm -rf /usr/sbin/nginx
We also have to remove the NGINX service from our system:
$ sudo rm -rf /usr/lib/systemd/system/nginx.service
Lastly, we remove nginx from our system:
$ sudo dnf remove nginx
Let’s note that dnf works similarly to yum. Likewise, we could instead run:
$ sudo yum remove nginx
If we had created a user for NGINX, then we’d need to delete it together with its directories:
$ sudo userdel -r nginx
If we check the status of our server, we won’t find the nginx.service unit, thus confirming that the server has been successfully uninstalled.
4. Conclusion
In this article, we’ve looked at how to uninstall NGINX from both Debian- and RPM-based distributions.
While looking at Debian, we noted that we have two options, apt purge and apt remove. If we don’t want to lose the settings while uninstalling, then we should use remove. Otherwise, we use purge. If we want to remove it completely or we want to perform a clean re-installation, we should use the purge command.
We further saw how to remove NGINX in RPM-based systems.
How To Uninstall NGINX on RHEL-Based OS, CentOS Stream 9

Today we will teach you on how to completely uninstall NGINX web server from the RHEL-based OS, CentOS Stream 9. In this cases you have some problems where it force you to uninstall NGINX from your CentOS 9 machine. E.g. there maybe some issues on your website applications which cannot run properly under Nginx web server. Instead, your web apps need other web servers that can run with rewrite rule, e.g. Apache .htaccess.
Therefore, it force you to switch to other web servers like Apache, OpenLiteSpeed (OLS), or maybe a LiteSpeed Enterprise Web Server (LSWS). It very simply, you can completely removed the Nginx web server in just a few step. Before doing this on your end, make sure to meet the following pre-requisites.
PREREQUISITES:
* Virtual / Physical Servers, VPS or Cloud * OS Distros with CentOS Stream 9 * Superuser Privileges (Root Access) * Familiar with CLI-Based or Command-Line Only * Gnome Terminal for Linux Desktop * PuTTy SSH Client for Windows or Mac * Powershell for Windows 10/11
1.) Login to Machine via SSH Console
In the first step you need to login to your machine via SSH console. Make sure to replace with your actual server IPv4 address and active SSH port.
$ ssh [email protected] -p4322 [email protected]'s password: Web console: https://open-source.project:9090/ or https://104.131.86.105:9090/ Last login: Tue May 31 04:52:09 2022 from 125.166.8.37
2.) Verify NGINX Version
Verify installed NGINX version on your CentOS 9 machine using the following command.
$ nginx -V nginx version: nginx/1.22.0 built by gcc 11.2.1 20220127 (Red Hat 11.2.1-9) (GCC) built with OpenSSL 3.0.1 14 Dec 2021 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
3.) Uninstall NGINX
Then simply run the following commands to completely uninstall or remove NGINX web server from your CentOS Stream 9. You can using either it “yum” command or “dnf” command if you running “DNF-Based” system.
$ yum remove nginx nginx-common -y No match for argument: nginx-common Dependencies resolved. ===================================================================================================================================================== Package Architecture Version Repository Size ===================================================================================================================================================== Removing: nginx x86_64 1:1.22.0-1.el9.ngx @nginx-stable 2.9 M Transaction Summary ===================================================================================================================================================== Remove 1 Package Freed space: 2.9 M Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Running scriptlet: nginx-1:1.22.0-1.el9.ngx.x86_64 1/1 Erasing : nginx-1:1.22.0-1.el9.ngx.x86_64 1/1 Running scriptlet: nginx-1:1.22.0-1.el9.ngx.x86_64 1/1 Verifying : nginx-1:1.22.0-1.el9.ngx.x86_64 1/1 Removed: nginx-1:1.22.0-1.el9.ngx.x86_64 Complete!
$ yum remove nginx* -y No such command: purge. Please use /usr/bin/yum --help It could be a YUM plugin command, try: "yum install 'dnf-command(purge)'" [root@open-source ~]# yum remove nginx* -y Dependencies resolved. ===================================================================================================================================================== Package Architecture Version Repository Size ===================================================================================================================================================== Removing: nginx-filesystem noarch 1:1.20.1-10.el9 @appstream 0 Transaction Summary ===================================================================================================================================================== Remove 1 Package Freed space: 0 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Erasing : nginx-filesystem-1:1.20.1-10.el9.noarch 1/1 Running scriptlet: nginx-filesystem-1:1.20.1-10.el9.noarch 1/1 Verifying : nginx-filesystem-1:1.20.1-10.el9.noarch 1/1 Removed: nginx-filesystem-1:1.20.1-10.el9.noarch Complete!
$ yum autoremove autoclean -y Last metadata expiration check: 0:51:08 ago on Tue 31 May 2022 01:27:45 PM EDT. Dependencies resolved. Nothing to do. Complete!
CONCLUSION:
You have successfully uninstall or remove NGINX web server completely from your CentOS Stream 9 machine. Then you can switch to another web server like Apache, or LiteSpeed to continue run your website or blog applications.