Skip to content

Instantly share code, notes, and snippets.

@mariocesar
Last active October 7, 2021 21:59
Show Gist options
  • Save mariocesar/b41b8b3535d170e3f3f8a9d85975bf7d to your computer and use it in GitHub Desktop.
Save mariocesar/b41b8b3535d170e3f3f8a9d85975bf7d to your computer and use it in GitHub Desktop.
Complete uwsgi Setup for production

How to use

mkdir -p var/run
mkdir -p var/log
mkdir -p public/static
mkdir -p public/media

uwsgi --ini uwsgi.ini
nignx {
server {
location @backend {
proxy_pass unix:///my/app/var/run/uwsgi.socket;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
# Proxy headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
}
}
[uwsgi]
master = true
auto-procname = true
enable-threads = false
single-interpreter = true
thread-stacksize = 512
processes = %k ;Use available numbers of cores in the machine
basedir = %d
chdir = %(basedir)
pidfile = %(basedir)var/run/uwsgi.pid
vacuum = true
show-config = true
log-master = true
log-slow = 1000
log-date = true
log-4xx = true
log-5xx = true
log-big = 102400
log-ioerror = true
log-zero = true
chmod-socket = 777
socket = %dvar/run/uwsgi.socket
pidfile = %dvar/run/uwsgi.pid
mimefile = %dmime.types
static-root = %dpublic
static-map = /static=%dpublic/static
static-map = /media=%dpublic/media
static-check = %dpublic/static
static-expires = %dpublic/static/.+\.[a-f0-9]{12}\.[a-z]+$ 2678400
load-file-in-cache =
load-file-in-cache-gzip =
static-gzip-ext = css
static-gzip-ext = js
static-gzip-ext = otf
route-uri = ^/static addheader:Cache-Control: public, max-age=31536000
route-uri = ^/static remheader:Set-Cookie
route-uri = ^/static remheader:Last-Modified
route = ^/favicon.ico$ static:%(static_root)icons/favicon.ico
route = ^/robots.txt$ static:%(static_root)robots.txt
route = ^/humans.txt$ static:%(static_root)humans.txt
env = PYTHONHASHSEED=random
chdir = %d
pythonpath = %dsrc
env = DJANGO_SETTINGS_MODULE=project.settings.production
wsgi-file = %dsrc/project/wsgi.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment