This repo shows how to deploy a Next.js app and a PostgreSQL database on a Linux Ubuntu server using Docker and Nginx. It showcases several key features of Next.js like caching, ISR, environment variables, and more.
If you would prefer to override the location of the cache, you can optionally store these entries to storage like Redis. If you are deploying a multi-container application, you will need to use this. For this demo, it's not required.
Env vars prefixed with NEXT_PUBLIC_ will be bundled and sent to the browser. app/protected/page.tsx shows an example of this. You can look at the source document to verify it has been bundled. This only makes sense for values you're comfortable being exposed to the browser.
If you want a secret env value to remain server only, you should only access it from a Server Component. app/page.tsx shows an example of this.
This value will be stabilized in Next.js 15 (which this repo is using) – the documentation currently shows it under an experimental object in next.config.js.