This guide will cover how to completely uninstall the Nginx web server (including its dependencies, modules, configuration files and logs) on Debian/Ubuntu-based Linux distros (e.g. Linux Mint, Pop!_OS, Elementary OS). It's useful when you're trying to reinstall a clean Nginx server.
The Nginx installed by the package manager (apt) is usually pretty outdated. Currently, v1.20.2 is the stable version of Nginx and Ubuntu LTS 20.04 (Focal) comes with version v1.18.0. Although to stay on the bleeding edge is never the goal of the Debian/Ubuntu release schedule, there are still some ways to obtain the latest version of Ngnix.
Nginx's server_name directive indicates the domain name it's listening on. But if none of the server blocks match the incoming request, it will still fall back to the last HTTP/HTTPS server block. So direct access by IP address will probably be caught by some route instead of being dropped, which is often not ideal.
Cloudflare CDN works just like a reverse proxy, it sits in front of your web servers and forwards client requests to them. So the requests reaching your server actually came from Cloudflare. To restore the original client's IP address, we'll be using ngx_http_realip_module in Nginx to retrieve them from headers.
More than 75% of all websites use HTTPS nowadays. Serving content over HTTPS is not only good practice for search engine optimization (SEO), but essential for security reasons, especially for those requests containing sensitive information.