Simple internal server error because running uwsgi keeps on deleting the .sock file
I'm trying to deploy my first django app by following these steps. The problem I have is that, for some reason, running uwsgi --emperor venv/vassals/ --uid www-data --gid www-data after activating my venv just seems to delete the .sock file in my root dir. I assume this is causing the problem because looking at the nginx logs at /var/log/nginx/error.log suggest so:
2021/10/11 22:09:57 [crit] 4281#4281: *6 connect() to unix:///var/www/dolphin/dolphin.sock failed (2: No such file or directory) while connecting to upstream, client: 81.102.82.13, server: example.com, request: "GET /favicon.ico HTTP/2.0", upstream: "uwsgi://unix:///var/www/dolphin/dolphin.sock:", host: "example.com", referrer: "https://example.com/
Here is my config file in /etc/nginx/sites-available (symlinked to sites-enabled):
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
# the upstream component nginx needs to connect to
upstream django {
server unix:///var/www/dolphin/dolphin.sock;
#server unix:/var/www/dolphin/dolphin.sock;
}
# configuration of the server
server {
listen 443 ssl;
server_name example.com;
charset utf-8;
# max upload size
client_max_body_size 75M;
# Django media and static files
location /media {
alias /var/www/dolphin/app/media;
}
location /static {
alias /var/www/dolphin/app/static;
}
# Send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /var/www/dolphin/uwsgi_params;
}
}
My dolphin_uwsgi.ini file:
[uwsgi]
# full path to Django project's root directory
chdir = /var/www/dolphin/
# Django's wsgi file
module = /var/www/dolphin/app/app/wsgi.py
# full path to python virtual env
home = /var/www/dolphin/venv/
# enable uwsgi master process
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /var/www/dolphin/dolphin.sock
# socket permissions
chmod-socket = 666
# clear environment on exit
vacuum = true
# daemonize uwsgi and write messages into given log
daemonize = /var/www/dolphin/uwsgi-emperor.log
I keep on getting an internal server error whenever loading the site in a browser for some reason (that is, after activating my venv and running uwsgi --emperor venv/vassals/ --uid www-data --gid www-data ) and I don't know why as the instructor seems to do it the same way as I am but it works for him.
Can anyone offer any insight here? Thank you
In case it might help, here's some of the potentially relevant parts of settings.py:
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
ALLOWED_HOSTS = ['example.com']
WSGI_APPLICATION = 'app.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'app/static')
]
MEDIA_URL = '/images/'
# full path to Django project's root directory chdir = /var/www/dolphin/ # Django's wsgi file module = /var/www/dolphin/app/app/wsgi.py
Since manage.py is inside dolphin/app, that's your Django project's root directory.
# full path to Django project's root directory
chdir = /var/www/dolphin/app
# Django's wsgi file
wsgi-file = app/wsgi.py
On the command line: uwsgi --socket dolphin.sock --chdir app --wsgi-file app/wsgi.py
Reference: https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html