Include uWSGI for production use, update pyproject.toml

This commit is contained in:
2023-09-18 12:30:19 +02:00
committed by root
parent ccaa3a4604
commit 09c6c35bb7
5 changed files with 128 additions and 37 deletions

View File

@ -33,4 +33,64 @@ for storing the music files.
14. Run ```./manage.py migrate``` to initialise the database and run all migrations.
15. Run ```./manage.py createsuperuser``` to create an administrator that is able to access the backend interface later
on.
16. Run ```./manage.py runserver``` to start the development server locally.
16. Run ```./manage.py runserver``` to start the development server locally.
Optionally you can enable debug mode by changing the boolean setting `DEBUG` in `marietje/marietje/setting/settings.py`
to `TRUE`.
## Production setup
For a production environment, the steps for the development setup can be followed up until running the actual server.
In a production environment, usage of uWSGI is recommended, so this needs to be installed.
Then, using the snippet below, a service file can be used to start the uWSGI in the Poetry environment.
```systemd
[Unit]
Description=MarietjeDjango website
After=syslog.target
[Service]
ExecStart=poetry run uwsgi \
--socket /run/uwsgi/MarietjeDjango.socket \
--uid=www-data \
--gid=www-data \
--module=marietje.wsgi \
--workers 2 --master \
--disable-write-exception
WorkingDirectory=/srv/MarietjeDjango/marietje
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
ProtectSystem=full
ProtectHome=yes
RuntimeDirectory=uwsgi
PrivateTmp=no
PrivateDevices=yes
ProtectControlGroups=yes
RemoveIPC=yes
[Install]
WantedBy=multi-user.target
```
The current production environment uses Nginx as webserver that connects to this WSGI socket.
Static files are served from `marietje/static`.
They can be loaded using `./manage.py collectstatic`.
A minimal Nginx configuration for both IPv4 and IPv6 as default would be the following.
```nginx
server {
listen 80 default_server;
listen [::]:80 default_server;
location /static {
alias /srv/MarietjeDjango/marietje/static;
}
location / {
uwsgi_pass unix:///run/uwsgi/MarietjeDjango.service;
include uwsgi_params;
}
}
```