Search code examples
uwsgiubuntu-20.04apache2.4django-4.0

Where do you create the ini file? (Uwsgi)


my reference:
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/uwsgi/

my project name:
'mysite'

my directories:
enter image description here

I create 'uwsgi.ini'.
enter image description here

then, I written in ini file.

[uwsgi]
chdir=/var/www/html/portfolio/mysite
module=mysite.wsgi:application
master=True
pidfile=/tmp/project-master.pid
vacuum=True
max-requests=5000
daemonize=/var/log/uwsgi/yourproject.log
single-interpreter=True

then, I command 'service apache2 restart'

I command this 'uwsgi --ini uwsgi.ini'

# uwsgi --ini uwsgi.ini
# open("/var/log/uwsgi/yourproject.log"): No such file or directory [core/logging.c line 288]

Solution

  • reference(japanese)

    Ubuntu server fails

    (console)
    # pip3 install uwsgi
      Installing collected packages: uwsgi
      Successfully installed uwsgi-2.0.20
    # mkdir -p /etc/uwsgi/vassals
    # cd /etc/uwsgi/vassals
    # source /var/www/html/venv/bin/activate
    
    # vi uwsgi.ini
    
    (uwsgi.ini(new))
    [uwsgi]
    chdir=/var/www/html/portfolio/mysite
    module=mysite.wsgi:application
    master=True
    pidfile=/tmp/project-master.pid
    vacuum=True
    max-requests=5000
    daemonize=/var/log/uwsgi/uwsgi.log
    single-interpreter=True
    
    (console)
    # adduser --group uwsgi-data
    # adduser --home /etc/uwsgi --no-create-home --shell /sbin/nologin --ingroup uwsgi-data --disabled-login uwsgi-data
      Adding user `uwsgi-data' ...
      Adding new user `uwsgi-data' (1001) with group `uwsgi-data' ...
      Not creating home directory `/etc/uwsgi'.
      Changing the user information for uwsgi-data
      Enter the new value, or press ENTER for the 
      default
            Full Name []:  # Empty and OK
            Room Number []:
            Work Phone []:
            Home Phone []:
            Other []:
      Is the information correct? [Y/n] Y
    
    (console)
    # chown -R uwsgi-data:uwsgi-data /etc/uwsgi
    # mkdir /var/log/uwsgi
    # chown -R uwsgi-data:uwsgi-data /var/log/uwsgi
    # vi /etc/systemd/system/emperor.uwsgi.service
    
    (emperor.uwsgi.service)
    [Unit]
    Description=uWSGI Emperor
    After=syslog.service
    
    [Service]
    # Find the configuration file that exists in "/etc/uwsgi/vassals" and start the uWSGI daemon.
    ExecStart=/var/www/html/venv/bin/uwsgi --master --emperor /etc/uwsgi/vassals
    RuntimeDirectory=uwsgi
    Restart=always
    KillSignal=SIGQUIT
    Type=notify
    StandardError=syslog
    NotifyAccess=all
    
    [Install]
    WantedBy=multi-user.target
    
    (console)
    # chmod 755 /etc/systemd/system/emperor.uwsgi.service
    # vi /etc/uwsgi/vassals/emperor.ini
    
    (emperor.ini)
    [uwsgi]
    emperor = /etc/uwsgi/vassals
    uid = uwsgi-data
    gid = uwsgi-data
    
    (console)
    # systemctl start emperor.uwsgi.service
    # systemctl status emperor.uwsgi.service
      ● emperor.uwsgi.service - uWSGI Emperor
         Loaded: loaded (/etc/systemd/system/emperor.uwsgi.service; disabled; vendor preset: enabled)
         Active: active (running)
    
    # service apache2 restart