When available, we recommend using
reflex deploy, but you can also host your
apps yourself in the meantime.
Clone your code to a server and install the requirements .
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:
config = rx.Config( app_name="your_app_name", api_url="http://app.example.com:8000", )
It is also possible to set the environment variable
API_URL at run time or
export time to retain the default for local development.
Then run your app in production mode:
$ reflex run --env prod
Production mode creates an optimized build of your app. By default, the static
the backend (event handlers) will be listening on port
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.
$ API_URL=http://app.example.com:8000 reflex export
This will create a
frontend.zip file with your app's minified HTML,
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
It is also possible to export the components without zipping. 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
Another option is to run your Reflex service in a container. For this
Dockerfile and additional documentation is available in the Reflex
project in the directory
For the build of the container image it is necessary to edit the
and the add the
to your project folder. The following changes are necessary in
config = rx.Config( app_name="app", api_url="http://app.example.com:8000", )
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
You can find the
requirements.txt in the
docker-example folder of the
The project structure should looks like this:
hello ├── .web ├── assets ├── hello │ ├── __init__.py │ └── hello.py ├── rxconfig.py ├── Dockerfile └── requirements.txt
After all changes have been made, the container image can now be created as follows.
$ docker build -t reflex-project:latest .
Finally, you can start your Reflex container service as follows.
$ docker run -d -p 3000:3000 -p 8000:8000 --name app reflex-project:latest