How To Uninstall Nginx From CentOS 7

On this short article we will learn how to uninstall/remove Nginx from CentOS 7 operating system.

Introduction

Nginx is known as a popular web server which is competing Apache Web server. NginX is growing so fast, because it has high concurrency, high performance while maintaining low memory usage. Sometime, as a system administrator or a webmaster, we were requested to uninstall Nginx due to the to certain reasons. On this short tutorial, we will learn how to uninstall/remove Nginx webmaster from CentOS 7.

We will describe deeply uninstall Nginx on the following steps.

  • Stop Nginx service
  • Remove Nginx user
  • Delete related Nginx installation directory

Stopping Nginx Service

The first step, to remove Nginx from CentOS system is to stop its service and remove auto start script. For this tasks we will do the following steps.

$ sudo systemctl status nginx
$ sudo systemctl stop nginx
$ sudo systemctl disable nginx.service

The output will be shown below :

[ramans@localhost ~]$ sudo systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Wed 2019-11-06 17:45:35 WIB; 10s ago
  Process: 4594 ExecReload=/bin/kill -s HUP $MAINPID (code=exited, status=0/SUCCESS)
  Process: 5017 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 5013 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 5008 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 5019 (code=exited, status=0/SUCCESS)

Nov 06 17:45:16 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
Nov 06 17:45:16 localhost.localdomain nginx[5013]: nginx: the configuration file /etc/nginx/ngin...ok
Nov 06 17:45:16 localhost.localdomain nginx[5013]: nginx: configuration file /etc/nginx/nginx.co...ul
Nov 06 17:45:16 localhost.localdomain systemd[1]: Started The nginx HTTP and reverse proxy server.
Nov 06 17:45:35 localhost.localdomain systemd[1]: Stopping The nginx HTTP and reverse proxy server...
Nov 06 17:45:35 localhost.localdomain systemd[1]: Stopped The nginx HTTP and reverse proxy server.
Hint: Some lines were ellipsized, use -l to show in full.





[ramans@localhost ~]$ sudo systemctl stop nginx.service
[ramans@localhost ~]$ sudo systemctl disable nginx.service
Removed symlink /etc/systemd/system/multi-user.target.wants/nginx.service.

Removing Nginx User

The next step is to remove nginx user from the system.

$ sudo userdel -r nginx

Output will be :

[ramans@localhost ~]$ sudo userdel -r nginx
userdel: nginx mail spool (/var/spool/mail/nginx) not found

Delete related Nginx installation Files

The next step is to remove related directories and dependencies files, the task will be done by following steps.

$ sudo rm -rf /etc/nginx
$ sudo rm -rf /var/log/nginx
$ sudo rm -rf /var/cache/nginx/
$ sudo rm -rf /usr/lib/systemd/system/nginx.service
$ sudo yum remove nginx

The output will be shown :

$ sudo rm -rf /etc/nginx
[ramans@localhost ~]$ sudo rm -rf /var/log/nginx
[ramans@localhost ~]$ sudo rm -rf /var/cache/nginx/
[ramans@localhost ~]$ sudo rm -rf /usr/lib/systemd/system/nginx.service
[ramans@localhost ~]$ sudo yum remove nginx
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.16.1-1.el7 will be erased
--> Processing Dependency: nginx for package: 1:nginx-mod-http-xslt-filter-1.16.1-1.el7.x86_64
--> Processing Dependency: nginx for package: 1:nginx-mod-http-perl-1.16.1-1.el7.x86_64
--> Processing Dependency: nginx for package: 1:nginx-mod-stream-1.16.1-1.el7.x86_64
--> Processing Dependency: nginx for package: 1:nginx-mod-mail-1.16.1-1.el7.x86_64
--> Processing Dependency: nginx for package: 1:nginx-mod-http-image-filter-1.16.1-1.el7.x86_64
--> Running transaction check
---> Package nginx-mod-http-image-filter.x86_64 1:1.16.1-1.el7 will be erased
--> Processing Dependency: nginx-mod-http-image-filter = 1:1.16.1-1.el7 for package: 1:nginx-all-modules-1.16.1-1.el7.noarch
---> Package nginx-mod-http-perl.x86_64 1:1.16.1-1.el7 will be erased
---> Package nginx-mod-http-xslt-filter.x86_64 1:1.16.1-1.el7 will be erased
---> Package nginx-mod-mail.x86_64 1:1.16.1-1.el7 will be erased
---> Package nginx-mod-stream.x86_64 1:1.16.1-1.el7 will be erased
--> Running transaction check
---> Package nginx-all-modules.noarch 1:1.16.1-1.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================
 Package                              Arch            Version                   Repository      Size
=====================================================================================================
Removing:
 nginx                                x86_64          1:1.16.1-1.el7            @epel          1.6 M
Removing for dependencies:
 nginx-all-modules                    noarch          1:1.16.1-1.el7            @epel          0.0  
 nginx-mod-http-image-filter          x86_64          1:1.16.1-1.el7            @epel           24 k
 nginx-mod-http-perl                  x86_64          1:1.16.1-1.el7            @epel           54 k
 nginx-mod-http-xslt-filter           x86_64          1:1.16.1-1.el7            @epel           24 k
 nginx-mod-mail                       x86_64          1:1.16.1-1.el7            @epel           99 k
 nginx-mod-stream                     x86_64          1:1.16.1-1.el7            @epel          171 k

Transaction Summary
=====================================================================================================
Remove  1 Package (+6 Dependent packages)

Installed size: 2.0 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 1:nginx-mod-http-image-filter-1.16.1-1.el7.x86_64                                 1/7 
  Erasing    : 1:nginx-mod-http-perl-1.16.1-1.el7.x86_64                                         2/7 
  Erasing    : 1:nginx-mod-http-xslt-filter-1.16.1-1.el7.x86_64                                  3/7 
  Erasing    : 1:nginx-mod-mail-1.16.1-1.el7.x86_64                                              4/7 
  Erasing    : 1:nginx-all-modules-1.16.1-1.el7.noarch                                           5/7 
  Erasing    : 1:nginx-mod-stream-1.16.1-1.el7.x86_64                                            6/7 
  Erasing    : 1:nginx-1.16.1-1.el7.x86_64                                                       7/7 
warning: file /var/log/nginx: remove failed: No such file or directory
warning: file /var/lib/nginx/tmp: remove failed: No such file or directory
warning: file /var/lib/nginx: remove failed: No such file or directory
warning: file /usr/lib/systemd/system/nginx.service: remove failed: No such file or directory
warning: file /etc/nginx/win-utf: remove failed: No such file or directory
warning: file /etc/nginx/uwsgi_params.default: remove failed: No such file or directory
warning: file /etc/nginx/uwsgi_params: remove failed: No such file or directory
warning: file /etc/nginx/scgi_params.default: remove failed: No such file or directory
warning: file /etc/nginx/scgi_params: remove failed: No such file or directory
warning: file /etc/nginx/nginx.conf.default: remove failed: No such file or directory
warning: file /etc/nginx/nginx.conf: remove failed: No such file or directory
warning: file /etc/nginx/mime.types.default: remove failed: No such file or directory
warning: file /etc/nginx/mime.types: remove failed: No such file or directory
warning: file /etc/nginx/koi-win: remove failed: No such file or directory
warning: file /etc/nginx/koi-utf: remove failed: No such file or directory
warning: file /etc/nginx/fastcgi_params.default: remove failed: No such file or directory
warning: file /etc/nginx/fastcgi_params: remove failed: No such file or directory
warning: file /etc/nginx/fastcgi.conf.default: remove failed: No such file or directory
warning: file /etc/nginx/fastcgi.conf: remove failed: No such file or directory
  Verifying  : 1:nginx-mod-stream-1.16.1-1.el7.x86_64                                            1/7 
  Verifying  : 1:nginx-all-modules-1.16.1-1.el7.noarch                                           2/7 
  Verifying  : 1:nginx-1.16.1-1.el7.x86_64                                                       3/7 
  Verifying  : 1:nginx-mod-mail-1.16.1-1.el7.x86_64                                              4/7 
  Verifying  : 1:nginx-mod-http-perl-1.16.1-1.el7.x86_64                                         5/7 
  Verifying  : 1:nginx-mod-http-xslt-filter-1.16.1-1.el7.x86_64                                  6/7 
  Verifying  : 1:nginx-mod-http-image-filter-1.16.1-1.el7.x86_64                                 7/7 

Removed:
  nginx.x86_64 1:1.16.1-1.el7                                                                        

Dependency Removed:
  nginx-all-modules.noarch 1:1.16.1-1.el7       nginx-mod-http-image-filter.x86_64 1:1.16.1-1.el7    
  nginx-mod-http-perl.x86_64 1:1.16.1-1.el7     nginx-mod-http-xslt-filter.x86_64 1:1.16.1-1.el7     
  nginx-mod-mail.x86_64 1:1.16.1-1.el7          nginx-mod-stream.x86_64 1:1.16.1-1.el7               

Complete!

Until this step, we have removed Nginx from CentOS 7 successfully.

Conclusion

On this short article we have shown you how to uninstall/remove Nginx service from CentOS 7 operating system. I hope this article will be helpful.

Add a Comment

Your email address will not be published. Required fields are marked *