Skip to content

Instantly share code, notes, and snippets.

@Shellbye
Last active August 9, 2016 08:35
Show Gist options
  • Save Shellbye/7e07c76a4c84d8a17066b2c691fc1bf1 to your computer and use it in GitHub Desktop.
Save Shellbye/7e07c76a4c84d8a17066b2c691fc1bf1 to your computer and use it in GitHub Desktop.
setup django site with nginx and uwsgi
#!/usr/bin/env bash
# install nginx & uwsgi
sudo apt-get install nginx
pip install uwsgi
# connect ngxin to django site
ln -s /path/to/your/mysite/mysite_nginx.conf /etc/nginx/sites-enabled/
# restart or start whatever needed
service nginx start
uwsgi --ini /path/to/uwsgi_config_file.ini
# update config file
nginx -s reload
# nginx.conf
# the upstream component nginx needs to connect to
upstream django_project {
server unix:/tmp/project.sock; # for a file socket
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
# server_name xxx.xxx.xxx.xxx; # substitute your machine's IP address or FQDN, use one of `listen` or `server_name`
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /path/to/project/media; # your Django project's media files - amend as required
}
location /static {
alias /path/to/project/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django_project;
include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
}
}
# uwsgi ini file
[uwsgi]
project_name = project_name_to_be_replaced
# Django-related settings
# the base directory (full path)
chdir = %d
# the absolute path of the directory containing the configuration file
# http://uwsgi-docs.readthedocs.io/en/latest/Configuration.html
# Django's wsgi file
module = %(project_name).wsgi
# %n the filename without extension
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
max-requests = 15
# the socket (use the full path to be safe
socket = /tmp/%(project_name).sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
#chown-socket = www-data:www-data
# clear environment on exit
vacuum = true
daemonize = /tmp/%(project_name).log
pidfile = /tmp/%(project_name).pid
# added 2014-08-25
#emperor = /etc/uwsgi/vassals
#uid = www-data
#gid = www-data
# added 2014-09-17
reload-on-as = 126
reload-on-rss = 126
enable-threads = true
pythonpath = %d
# the absolute path of the directory containing the configuration file
env = LANG=en_US.UTF-8
# http://stackoverflow.com/questions/10396141/strange-unicodeencodeerror-using-os-path-exists
#!/usr/bin/env bash
git pull
uwsgi --stop /tmp/project_uwsgi.pid
/etc/init.d/nginx stop
/etc/init.d/nginx start
uwsgi --ini uwsgi.ini
#!/usr/bin/env bash
sudo apt-get install mysql-client-core-5.7
# EnvironmentError: mysql_config not found
sudo apt-get install libmysqlclient-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment