1. Check whether the nginx service is running, and shut down the service if it is running.
ps -ef|grep nginx
/usr/local/nginx/sbin/nginx -s stop
2. Find and delete nginx related files.
whereis nginx
find / -name nginx
rm -rf /usr/local/nginx
3. Uninstall nginx dependencies.
yum remove nginx
At this point, nginx has been uninstalled, and other versions of nginx services can be reinstalled.
How to install the nginx service correctly, please see here: Detailed steps to install nginx under Linux