This CORS configuration is not part of the grafana code/config.
Nginx is a reverse proxy server and is just a suggestion. You could do the same thing with Apache, IIS (if you are on Windows) and lots of other servers. Nginx is just the most popular option right now.
A proxy server is a go‑between or intermediary server that forwards requests for content from multiple clients to different servers across the Internet. A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network and directs client requests to the appropriate backend server. A reverse proxy provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.
Here’s a guide on installing nginx on Ubuntu: How To Install Nginx on Ubuntu 16.04 | DigitalOcean