We recommend using reflex deploy but you can also host your apps yourself.
Clone your code to a server and install the requirements.
API URL
Edit your rxconfig.py file and set api_url to the publicly accessible IP address or hostname of your server, with the port :8000 at the end. Setting this correctly is essential for the frontend to interact with the backend state.
For example if your server is at app.example.com, your config would look like this:
It is also possible to set the environment variable API_URL at run time or export time to retain the default for local development.
Production Mode
Then run your app in production mode:
$ reflex run --env prod
Production mode creates an optimized build of your app. By default, the static frontend of the app (HTML, Javascript, CSS) will be exposed on port 3000 and the backend (event handlers) will be listening on port 8000.
Reverse Proxy and Websockets
Because the backend uses websockets, some reverse proxy servers, like nginx or apache, must be configured to pass the Upgrade header to allow backend connectivity.
Exporting a Static Build
Exporting a static build of the frontend allows the app to be served using a static hosting provider, like Netlify or Github Pages. Be sure api_url is set to an accessible backend URL when the frontend is exported.
This will create a frontend.zip file with your app's minified HTML, Javascript, and CSS build that can be uploaded to your static hosting service.
It also creates a backend.zip file with your app's backend python code to upload to your server and run.
You can export only the frontend or backend by passing in the --frontend-only or --backend-only flags.
It is also possible to export the components without zip it separate. To do this, use the --no-zip parameter. This provides the frontend in the .web/_static/ directory and the backend can be found in the root directory of the project.
Reflex Container Service
Another option is to run your Reflex service in a container. For this purpose, a Dockerfile and additional documentation is available in the Reflex project in the directory docker-example.
For the build of the container image it is necessary to edit the rxconfig.py and the add the requirements.txt to your project folder. The following changes are necessary in rxconfig.py:
Notice that the api_url should be set to the externally accessible hostname or IP, as the client browser must be able to connect to it directly to establish interactivity.
You can find the requirements.txt in the docker-example folder of the project too.