Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save llazzaro/11382653 to your computer and use it in GitHub Desktop.
Save llazzaro/11382653 to your computer and use it in GitHub Desktop.
# This is a step by step tutorial on how to run uwsgi in emperor mode,
# behind nginx on Fedora 20. I'll add to the tutorial as time goes on.
# SeLinux will likely be a pain (even in permissive mode), so please see my comment on how to fix it.
sudo yum upgrade
sudo yum install nano yum-utils gcc uwsgi-plugin-python3 nginx
yum-builddep python3-psycopg2
yum-builddep python3-Pillow
1. usermod -a nginx -G uwsgi
2. ???
3. Place the following in /etc/uwsgi.d/me_vandorjw.ini
#
# me_vandorjw.ini
#
[uwsgi]
#variables
projectname = vandorjw
base = /var/sites/me/vandorjw
plugins = python3
chdir = %(base)/src/%(projectname)
pythonpath = %(base)/src/%(projectname)
virtualenv = %(base)/venv/%(projectname)
env = DJANGO_SETTINGS_MODULE=%(projectname).settings
module = django.core.handlers.wsgi:WSGIHandler()
socket = /run/uwsgi/%n.socket
chmod-socket = 660
logto = %(base)/logs/uwsgi.log
4. sudo chown uwsgi:uwsgi /etc/uwsgi.d/me_vandorjw.ini
5. place the following in /etc/nginx/conf.d/me_vandorjw.conf
server {
listen 80;
server_name vandorjw.me;
access_log /var/sites/me/vandorjw/logs/access.log;
error_log /var/sites/me/vandorjw/logs/error.log;
location /static/ {
alias /var/sites/me/vandorjw/static/;
}
location /media/ {
alias /var/sites/me/vandorjw/media/;
}
location / {
uwsgi_pass unix:///run/uwsgi/me_vandorjw.socket;
include uwsgi_params;
}
error_page 404 /404.html;
location = /40x.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
5. Grab this script. Place it in your home dir, calling it pyvenv3.py
http://docs.python.org/3/library/venv.html#an-example-of-extending-envbuilder
6. sudo mkdir -p /var/sites/me/vandorjw/
7. sudo chown -R fedora /var/sites
7b. alternatively, use ACL
8. cd /var/sites/me/vandorjw/
9. mkdir venv logs media static src
10. python3 ~/pyvenv3.py venv/vandorjw
11. source venv/vandorjw/bin/activate
12. pip install django, south, pillow, psycopg2
13. cd src
14. django-admin.py startproject vandorjw
15. cd ..
15. sudo semanage fcontext -a -t httpd_log_t -r s0 "/var/sites/me/vandorjw/logs(/.*)?"
16. sudo restorecon -R logs/
17. touch /var/sites/me/vandorjw/logs/uwsgi.log
17. sudo chgrp uwsgi /var/sites/me/vandorjw/logs
17. sudo chown uwsgi:uwsgi /var/sites/me/vandorjw/logs/uwsgi.log
17. sudo systemctl enable nginx.service
18. sudo systemctl enable uwsgi.service
19. Place the following line in /etc/tmpfiles.d/uwsgi.conf
D /run/uwsgi 0770 uwsgi uwsgi -
Restart Server - Enjoy Life
@frafra
Copy link

frafra commented Jun 21, 2018

# usermod -a nginx -G uwsgi
# echo 'D /run/uwsgi 0770 uwsgi uwsgi -' > /etc/tmpfiles.d/uwsgi.conf

...combined with chmod-socket = 660 in the uwsgi configuration file, fixed my permission issue. Thank you :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment