nginx:stable-alpine as its base and ships with a custom Nginx site configuration. The file is copied into the image at /etc/nginx/conf.d/default.conf during the Docker build.
Full configuration
nginx.conf
Configuration walkthrough
Server block
server_name localhost is suitable for containerised deployments where the container hostname is not publicly resolved. When placing Nginx behind a reverse proxy or load balancer, this value can remain as-is; the outer proxy handles the public hostname.
Static file serving
root /usr/share/nginx/html— serves files from the directory where the Vite build output (dist/) is copied during the Docker build.index index.html index.htm— servesindex.htmlwhen a directory is requested.try_files $uri $uri/ /index.html— the SPA fallback. Nginx first tries to serve the exact file requested, then a directory with that name, and finally falls back toindex.html. This ensures that React Router routes like/explore/destinations/123are handled by the client-side router rather than returning a 404.
Error pages
/50x.html page that Nginx includes by default. The page is served from the same web root as the application.
Customising the configuration
Changing the listening port
To serve on a port other than 80, updatelisten and the EXPOSE directive in the Dockerfile:
docker run port mapping accordingly:
Adding an API reverse proxy
If the backend API is on the same Docker network, you can proxy/api/ requests directly from Nginx rather than requiring the browser to make cross-origin requests:
att-backend:3000 with the hostname and port of your backend container.
When using this proxy approach, set
VITE_API_BASE_URL to /api (a relative path) so the browser sends requests to the same origin, which Nginx then forwards upstream.Gzip compression
The basenginx:stable-alpine image has the gzip module compiled in. Add the following inside the server block to compress text-based assets:
Cache headers for static assets
Vite fingerprints JavaScript and CSS bundles with content hashes, making them safe to cache indefinitely. Add alocation block to set long-lived cache headers for those assets:
location / block so Nginx matches it first.
Adding SSL/TLS
The containerised Nginx does not handle TLS termination by default. The recommended approach for production is to terminate TLS at an upstream load balancer or reverse proxy (such as AWS ALB, GCP Cloud Load Balancing, Caddy, or a separate Nginx instance), and forward plain HTTP to the container on port 80. If you need TLS directly in the container, refer to the Nginx HTTPS server documentation and mount your certificates as Docker volumes:Applying a custom configuration
To replace the default configuration without rebuilding the image, mount your ownnginx.conf at runtime:
