Nginx configuration can be confusing sometimes. You could simply mess up your whole server while playing around with it and following steps on every random tutorial that you encounter online.
In that situation, instead of trying to fix the bug that you created yourself, it’s sometimes useful to just start fresh and reset the nginx installation on your system.
The following method is also useful if you tried to manually remove nginx by removing the nginx folder from /etc/nginx/
and now everything breaks and you can’t reinstall it again etc.
To remove nginx completely from your system, using this command:
sudo apt-get purge nginx nginx-common nginx-full
Now once that’s gone, now you can install fresh by using the command:
sudo apt-get install nginx
In some cases, if you can’t remove nginx completely using the command above, you can also try:
sudo dpkg --force-confmiss -i /var/cache/apt/archives/nginx-common_*.deb
Once everything is set, now you can start configuring your nginx server again from start.
Note that it is always wiser to test new configurations in a new test environment instead of trying them directly on your live webserver or otherwise any live production environment.