Install varnish with below command

sudo apt update
sudo apt install varnish

Varify varnish version

varnishd -V

Go to in Admin

Stores -> Configuration -> Advanced -> System -> Full Page Cache

Choose option Varnish cache  and save configuration

Download VCL for varnish 6 from same page from admin

sudo mv /etc/varnish/default.vcl /etc/varnish/default.vcl.backup
sudo nano /etc/varnish/default.vcl

Paste content from downloaded VCL file from admin to default.vcl & restart varnish and nginx

sudo systemctl restart nginx varnish
php bin/magento cache:flush

Remove var/page_cache folder and visit the website after that verify if page_cache folder is empty,  That confirms that varnish is working