install flask/quart/starlette websites into nginx and systemd
Project description
flask-nginx aka "footprint" 👣
I use this to generate config files for my flask apps. Currently systemd and nginx. It only depends on jinja2 and click which a also dependencies of flask/quart.
Will also work with starlette apps too e.g. fastapi.
It is intended to be installed into the same virtual environment that the flask app inhabits so it can introspect the app (for static folders mainly).
export FLASK_APP=your_package.wsgi
footprint config nginx www.example.com > example.conf
footprint config nginx-install example.conf
# install in ~/.config/systemd/user
export FLASK_APP=your_package.wsgi
footprint config systemd --user > example.service
footprint config systemd-install --user example.service
will install nginx and systemd files that will statically serve you 'static' assets and run the Flask app with gunicorn.
Mostly I've found that confectioning these files by hand are highly error prone. These commands will at least get the absolute pathnames correct :)
footprint will install a Quart or a starlette/fastapi using the --asgi flag.
Install with:
uv add flask-nginx
python -m pip install flask-nginx
If footprint finds a pyproject.toml file in the current directory
if will try to load [tool.footprint] values into its global configuration object.
Unless you specify a configuration file yourself with footprint -c confg.toml ....
nginx, systemd and all that
Note that these configuration generating functions are not infallible. Please examine the generated configure files carefully! They are mainly useful for getting the directory names correct etc. So if you move your repo then you can easily regenerate and reinstall the files.
- Nginx Docs. Also and Proxy
Test an nginx config with e.g.:
cd ~/Sites/websites/ppr
export FLASK_APP=ppr.wsgi
footprint config nginx example.org | footprint config nginx-run -
This will run nginx at the terminal listening on port 5000 and run the backend website.
To install a website:
footprint config nginx example.org -o website.conf
footprint config systemd [--user] -o website.service
# nginx requires sudo (default) or su
footprint config nginx-install website.conf
# if you can install into ~/.config/systemd/user
footprint config systemd-install [--user] website.service
You can test this locally by editing /etc/hosts and adding a line:
127.0.0.1 example.org
to the file.
REMEMBER: Unix file permissions mean that you should edit /etc/nginx/nginx.conf
and change user www-data; to user {you}; Or (recursively) change the owner on
all the repo directories to www-data.
If you install as "user" (i.e. footprint config systemd --user ...) then
to ensure that the user systemd starts at boot time use: sudo loginctl enable-linger <user>
See here:
But what’s the real reason for having user services? To answer that, we have to realize when the enabled service starts and stops. If we enable a user service, it starts on user login, and runs as long as there is a session open for that user. Once the last session dies, the service stops.
See digitalocean.com here for a tutorial about serving flask from nginx.
.flaskenv
If a .flaskenv is found in the repo directory then nginx and systemd will
read paramters from that file. The keywords should be uppercase version of
the known parameters. Unknown parameters will be ignored.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_nginx-0.9.5.tar.gz.
File metadata
- Download URL: flask_nginx-0.9.5.tar.gz
- Upload date:
- Size: 34.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5276648e19c709df1de91a8592c85a89157d299001dc8b2f2dfceaf4811661d4
|
|
| MD5 |
4fd9e839cab98289fa46f1a5afe93fea
|
|
| BLAKE2b-256 |
ec88d358b8c5b92eafdd52a48a9de5efeac27422adb16d23af6877a01afdb8a0
|
File details
Details for the file flask_nginx-0.9.5-py3-none-any.whl.
File metadata
- Download URL: flask_nginx-0.9.5-py3-none-any.whl
- Upload date:
- Size: 50.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c577ef4873d8275ff0dd4c3250c1c617f66a0d8ee21b0e01a93b8dd3f743554d
|
|
| MD5 |
f70e05174a87f71e71ccda5eb4c5c401
|
|
| BLAKE2b-256 |
04cfc160fe339d06afcf6a13fdef51c7475fa0511ae8cf79032ed8fdce7c41cd
|