Ubuntu
Deploy your application with uWSGI and Nginx on Ubuntu¶
Ubuntu is a GNU/Linux operating system that can run the Web Application Server uWSGI and the Web Server Nginx.
Ubuntu versions below 20.04¶
In versions before Ubuntu 20.04, the pre-installed Python versions are older than 3.9, the oldest version supported by Taipy. If you are in that case, please install Python 3.9 or above.
Prepare your machine¶
The following software should be installed on your target machine:
-
pip: for installing Python3 packages.
-
uwsgi and gevent: the web application server and its workers that will run the Taipy applications.
-
nginx: the web server for the Internet exposition.
You can install all of these packages by running the following command:
sudo apt update -y
sudo apt install -y python3-pip nginx
sudo pip install uwsgi gevent
sudo ln -s `pwd`/.local/bin/uwsgi /usr/bin/uwsgi
Note
If you are using a SQL database based on Microsoft SQL Server, you need to install your corresponding Microsoft ODBC Driver for SQL Server.
Run the application locally¶
If you want to deploy the following application:
from taipy import Gui
Gui(page="# Getting started with *Taipy*").run()
This would be placed in a file called app.py.
You need to create a requirements.txt file that contains:
taipy
On your local machine, start the application by executing the following:
$ pip install -r requirements.txt
Collecting taipy
<-- Truncate -->
Successfully installed taipy
$python app.py
* Server starting on http://127.0.0.1:5000
* Serving Flask app 'Taipy' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
<-- Truncate -->
The application is running locally; you can access it with the browser on the URL http://127.0.0.1:5000/.
Note
The message:
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
This message is generated by the Werkzeug WSGI web application library that Flash depends on and will disappear when using the web server.
Some versions of Werkzeug may even raise an exception in that situation, preventing you from running the application. You will then need to set the allow_unsafe_werkzeug configuration parameter to True (or set the allow_unsafe_werkzeug parameter of
Gui.run()
to True).
Prepare the application for deployment¶
Deploying your application to a remote environment needs a bit of configuration.
Make sure you turn off the Debug mode (which is the default) by setting the
debug parameter of Gui.run()
to False.
You must also inform Taipy not to run the application server on its own but rather delegate the
execution by setting the parameter run_server
of the call to Gui.run()
to False.
The name of the variable where the web application is stored is used in the uWSGI configuration:
this allows the web server to load the web application:
from taipy import Gui
gui_service = Gui(page="# Getting started with *Taipy*")
web_app = gui_service.run(debug=False, run_server=False)
Make sure you upload this code on your target machine and install your dependencies with pip.
Entry point
The entry point filename and the application variable name are important for the proper configuration of the uWSGI web application server. Please, keep them as is or adapt the configuration.
uWSGI application server¶
To expose your application over the Internet, you must use uWSGI instead of Flask as the application server. You would then leverage Nginx to expose the application.
uWSGI can be started manually. But, generally, it's better to start the application automatically when the machine starts. To order to do that, you should use Systemd which is installed by default on Ubuntu.
From the directory where app.py is located, run the following command to generate an adapted file for Systemd:
echo """
[Unit]
Description=App
After=syslog.target
[Service]
ExecStart=uwsgi --http 127.0.0.1:5000 --gevent 1000 --http-websockets --module app:web_app
WorkingDirectory=`pwd`
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
User=`whoami`
[Install]
WantedBy=multi-user.target
""" > app.uwsgi.service
sudo mv app.uwsgi.service /etc/systemd/system/app.uwsgi.service
Now, you can start your application automatically at startup time of your machine by issuing the following commands:
sudo systemctl start app.uwsgi.service
sudo systemctl enable app.uwsgi.service
The application is now running locally but is not accessible yet from the Internet.
Exposing to the Internet¶
To expose your application on the Internet, you should use Nginx.
Change the content of /etc/nginx/sites-enabled/default
with the following:
server {
listen 80;
location / {
proxy_pass http://localhost:5000;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
}
}
sudo systemctl restart nginx
Your application is now accessible over the Internet!
HTTPS support
This configuration is only for HTTP. If you need an HTTPS connection, please read the Nginx documentation.