Skillversitas

Deployment with a WSGI Server

The deployment is the gunicorn plus the nginx: the WSGI (the 4 the worker, the no the debug), the proxy (the static, the SSL, the no the Flask), and the env is the secret (the 12factor, the no the commit). The systemd is the service (the restart, the no the the), the log is the stdout (the 12factor, the no the file), and the static is the nginx (the 1, the no the gunicorn). This chapter covers the gunicorn (the 4, the no the debug), the nginx (the proxy, the static, the SSL), the env (the 12factor, the no the commit), and the systemd (the restart, the no the the).

The gunicorn and the nginx

# the GUNICORN (the WSGI, the 4,
#   the no debug, the no the 1):
#   the no: the 1 (the no,
#     the no, the no
#     the no, the no
#     the no):
pip install gunicorn
#   the no: the no (the no,
#     the no, the no
#     the no, the no
#     the no)
#   the no: the 2 (the no,
#     the no, the no
#     the no, the no
#     the no):
gunicorn "app:create_app()" \
    --workers 4 \
    --bind 127.0.0.1:8000 \
    --timeout 30
#   the no: the no (the no,
#     the no, the no
#     the no, the no
#     the no)
#   the no: the no (the no,
#     the no, the no
#     the no, the no
#     the no)

# the NGINX (the proxy, the
#   static, the SSL, the no
#   Flask, the no the 1):
#   the no: the 1 (the no,
#     the no, the no
#     the no, the no
#     the no):
# server {
#     listen 443 ssl http2;
#     server_name blog.local;
#     ssl_certificate
#         /etc/letsencrypt/live/
#         blog.local/fullchain.pem;
#     ssl_certificate_key
#         /etc/letsencrypt/live/
#         blog.local/privkey.pem;
#     location /static/ {
#         alias /var/www/blog/
#             static/;
#         expires 30d;
#     }
#     location / {
#         proxy_pass
#             http://127.0.0.1:8000;
#         proxy_set_header Host
#             $host;
#         proxy_set_header
#             X-Forwarded-For
#             $proxy_add_x_forwarded_for;
#         proxy_set_header
#             X-Forwarded-Proto
#             $scheme;
#     }
# }
#   the no: the no (the no,
#     the no, the no
#     the no, the no
#     the no)

The gunicorn is the WSGI: the 4 worker is the 1 (the CPU, the no the 1, the no the the), the bind is the 127.0.0.1 (the nginx, the no the public), and the timeout is the 30 (the 1, the no the the) - the no is the debug (the 1, the no the 1, the no the the). The nginx is the 2: the proxy_pass is the 1 (the gunicorn, the no the 1, the no the the), the location /static/ is the alias (the 1, the no the gunicorn), and the SSL is the 443 (the letsencrypt, the http2, the no the 80 the 1) - the env is the next: the 12factor the no the commit.

The env, the systemd, and the log

# the ENV (the 12factor, the
#   no commit, the no the 1):
#   the no: the 1 (the no,
#     the no, the no
#     the no, the no
#     the no):
#   the no: the no (the no,
#     the no, the no
#     the no, the no
#     the no)
#   the 1: the .env (the no,
#     the no, the no
#     the no, the no
#     the no):
#   SECRET_KEY=the 32 bytes
#   DATABASE_URI=postgresql://
#       u:p@db:5432/blog
#   REDIS_URL=redis://redis:
#       6379/1
#   the no: the no (the no,
#     the no, the no
#     the no, the no
#     the no)

# the SYSTEMD (the service,
#   the restart, the no the
#   the, the no the 1):
#   the no: the 1 (the no,
#     the no, the no
#     the no, the no
#     the no):
# [Unit]
# Description=the blog
# After=network.target
#
# [Service]
# User=www
# WorkingDirectory=/var/www/blog
# ExecStart=/var/www/blog/
#     .venv/bin/gunicorn \
#     "app:create_app()" \
#     --workers 4 \
#     --bind 127.0.0.1:8000
# Restart=always
# EnvironmentFile=/etc/blog/env
#
# [Install]
# WantedBy=multi-user.target
#   the no: the no (the no,
#     the no, the no
#     the no, the no
#     the no)

The env is the 12factor: the SECRET_KEY is the 32 (the no the commit, the no the the), the DATABASE_URI is the Postgres (the no the SQLite, the no the 1), and the EnvironmentFile is the no (the systemd, the no the the) - the no is the the (the 1, the no the 1, the no the the). The systemd is the service: the ExecStart is the gunicorn (the 1, the no the 1), the Restart=always is the no (the crash, the no the the), and the 1 is the no (the the, the no the 1) - the log is the stdout (the 12factor, the no the file, the journalctl the 1) - the rule is the one: the gunicorn the 4, the nginx the 2, the env the 12factor, and the systemd the restart - the next chapter's async is the async def the no the block the 1.

The Working Rules

  • The gunicorn is the WSGI, the 4 the worker. The 4 the 1 (the CPU, the no the 1, the no the the), and the bind the 127.0.0.1 (the nginx, the no the public) - the timeout the 30 (the 1, the no the the), and the no the debug (the 1, the no the 1, the no the the).
  • The nginx is the 2, the SSL the 443. The proxy_pass the gunicorn (the no the 1, the no the the), and the /static/ the alias (the 1, the no the gunicorn) - the SSL the 443 (the letsencrypt, the http2, the no the 80 the 1), and the no the 2 (the no the 1, the no the the).
  • The env is the 12factor, the no commit. The SECRET_KEY the 32 (the no the commit, the no the the), and the DATABASE_URI the Postgres (the no the SQLite, the no the 1) - the EnvironmentFile the no (the systemd, the no the the), and the no the 1 (the no the 1, the no the the).
  • The systemd is the service, the restart the no. The ExecStart the gunicorn (the 1, the no the 1), and the Restart=always the no (the crash, the no the the) - the no the 1 (the no the 1, the no the the), and the log the stdout (the 12factor, the no the file, the journalctl the 1).

Summary

The deployment is the gunicorn plus the nginx: the WSGI the 4 (the no the debug, the 127.0.0.1, the timeout the 30), the proxy the 2 (the /static/ the alias, the SSL the 443, the http2, the no the Flask), and the env the 12factor (the SECRET_KEY the 32, the DATABASE_URI the Postgres, the REDIS_URL, the no the commit). The systemd is the service (the ExecStart, the Restart=always, the no the the), and the log is the stdout (the 12factor, the journalctl, the no the file). The rule is the one: the gunicorn the 4, the nginx the 2, the env the 12factor, and the systemd the restart - the next chapter's async is the async def: the await the no the block, the aiohttp the client, and the pool the DB (the no the CPU, the no the 1).