Deploy React.js and other static sites¶
Overview¶
A React build is just static files. tsuru serves them with the static platform,
an nginx setup that serves whatever is in the deployed directory. The flow has two steps on your
machine (build the site) and one on tsuru (deploy the build directory).
Creating the app¶
tsuru app create <app-name> static
Build¶
Generate the production build with your toolchain, for example:
npm run build
Deploy¶
Add two files to the build directory and deploy it. The examples below work for most
single-page apps: nginx.conf rewrites unknown paths to index.html, tsuru.yml declares the
healthcheck.
cd build
wget https://raw.githubusercontent.com/tsuru/platforms/refs/heads/master/examples/static-reactjs/nginx.conf
wget https://raw.githubusercontent.com/tsuru/platforms/refs/heads/master/examples/static-reactjs/tsuru.yml
tsuru app deploy -a <app-name> .
Customizing nginx¶
nginx.confin the deployed root replaces the platform's defaultnginx.conf. Start from a copy of it: it contains directives tsuru relies on, such asport_in_redirect offand listening onPORT. The platform validates the file withnginx -tduring the deploy.-
NGINX_PKGpicks the Ubuntu nginx flavour installed at deploy time:nginx(default),nginx-core,nginx-full,nginx-lightornginx-extras. Any other value fails the deploy.tsuru env set -a <app-name> NGINX_PKG=nginx-extras