Deploying owl
Here I am considering launching an application on a server using uWSGI
. You can choose any other WSGI server.
The principle of the owl deployment is no different from the deployment of a typical Flask application. See Flask docs: Deployment Options.
Install web-server
uWSGI
will run from a virtualenv and be supported by a supervisor
. nginx
will be used as a reverse proxy.
sudo apt install -y nginx supervisor gcc
source /path/to/virtualenv/bin/activate
pip install uwsgi
uWSGI config
Save as uwsgi.ini
:
[uwsgi]
master = true
strict = true
vacuum = true
enable-threads = true
single-interpreter = true
processes = 4
threads = 2
die-on-term = true
# Logging settings
logger = file:logfile=/tmp/uwsgi.log,maxsize=2000000
# UNIX-socket
socket = /tmp/uwsgi.sock
chmod-socket = 666
chdir = /path/to/owl
module = wsgi
callable = app
Don't forget add www-data
to your user's group:
usermod -a -G USERGROUP www-data
nginx virtual host config
Replace example.org
with your domain and set correct paths:
server {
listen 80;
#listen 443 ssl http2;
root /path/to/site/;
server_name example.org www.example.org;
# Let's Encrypt SSL certifcate
#ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
#ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;
# Redirect to HTTPS
#if ($scheme != "https") {
# return 301 https://$host$request_uri;
#}
# Base Auth
#location / {
# auth_basic "Authentication required";
# auth_basic_user_file /var/www/example.org/.htpasswd;
#}
location / {
# uWSGI proxy
include uwsgi_params;
uwsgi_pass unix:/tmp/uwsgi.sock;
}
location ~* \.(css|js|jpg|jpeg|png|gif|woff|ttf)$ {
expires 1M;
add_header Cache-Control public;
}
}
run_uwsgi.sh
This script will be activate virtualenv and run uWSGI with their config file.
#!/bin/bash
source /path/to/virtualenv/bin/activate
uwsgi --ini /path/to/uwsgi.ini
supervisor config
Place file at /etc/supervisor/conf.d/
with .conf
extension. Replace USER to your username.
[program:example.org.uwsgi]
command = /path/to/run_uwsgi.sh
user = USER
process_name = %(program_name)s
numprocs = 1
autostart = true
autorestart = true
stopsignal = QUIT
Run
service nginx restart
service supervisor restart