Skip to content

Instantly share code, notes, and snippets.

@k4ml
Forked from ptone/_webfaction_setup.rst
Created September 17, 2012 02:58
Show Gist options
  • Save k4ml/3735326 to your computer and use it in GitHub Desktop.
Save k4ml/3735326 to your computer and use it in GitHub Desktop.
setting up a stack on webfaction
worker_processes 1;
pid pid/nginx.pid;
error_log log/nginx-error.log;
events {
worker_connections 1024;
}
http {
# Some sensible defaults.
include mime.types;
default_type application/octet-stream;
keepalive_timeout 10;
client_max_body_size 20m;
sendfile on;
gzip on;
# Directories
client_body_temp_path tmp/client_body/ 2 2;
fastcgi_temp_path tmp/fastcgi/;
proxy_temp_path tmp/proxy/;
uwsgi_temp_path tmp/uwsgi/;
# Logging
access_log log/nginx-access.log combined;
# uWSGI serving Django.
# upstream django {
# Distribute requests to servers based on client IP. This keeps load
# balancing fair but consistent per-client. In this instance we're
# only using one uWGSI worker anyway.
# ip_hash;
# server unix:sock/uwsgi.sock;
# }
server {
listen 50218;
server_name nginx.ptone.com;
charset utf-8;
# Django admin media.
location /static/admin/ {
alias lib/python2.6/site-packages/django/contrib/admin/media/;
}
# Your project's static media.
location /static/ {
alias test_project/media/;
}
# Finally, send all non-media requests to the Django server.
location / {
# uwsgi_pass django;
uwsgi_pass unix:sock/uwsgi.sock;
include uwsgi_params;
}
}
}

Getting your basic python settings sorted out

https://gist.github.com/902200:

mkdir -p ~/bin ~/lib/python2.6/site-packages
easy_install-2.6 --prefix=$HOME pip
pip install virtualenv

Setting up a nginx-uwsgi-django stack

Setting up the webfaction app

create custom port listening app:

cd webapps/teststack/
virtualenv venv
source venv/bin/activate
mkdir pkg
cd pkg

Download and make packages

http://nginx.org/en/download.html#stable_versions

curl http://nginx.org/download/nginx-0.8.54.tar.gz | tar -xvz

uwsgi module included since 0.8.40 nginx

http://projects.unbit.it/uwsgi/wiki/RunOnNginx

upload progress module:

http://github.com/masterzen/nginx-upload-progress-module

git clone https://github.com/masterzen/nginx-upload-progress-module.git

get uwsgi itself: I've found this latest version has compile errors on webfaction while this does not:

curl http://projects.unbit.it/downloads/uwsgi-0.9.6.8.tar.gz | tar -xz
cd uwsgi-x-x-x-x
make -f Makefile.Py26
cp uwsgi $VIRTUAL_ENV/bin/
cd ../nginx-0.8.54/
./configure --add-module=../uwsgi-0.9.6.8/nginx/ --add-module=../nginx-upload-progress-module/
make

expect to see errors about deprecated sys_errlist: http://nginx.org/en/docs/sys_errlist.html

cp objs/nginx $VIRTUAL_ENV/bin/

Set up Django project

cd out to webapps/<appname>
django-admin.py startproject test_project
cd test_project/
mkdir -p etcs/production
ln -s etcs/production/ ./etc
cd ..
cp pkg/nginx-0.8.54/conf/mime.types test_project/etcs/production/
cp pkg/uwsgi-0.9.6.8/nginx/uwsgi_params test_project/etcs/production/
cd venv
mkdir tmp/ sock/ pid/ log/

get the django project settings and urls set up for admin to work manage.py collectstatic

Get the runtime stuff setup

get project on python path:

cd venv/<site-packages>
ln -s $HOME/webapps/test_project .

start up nginx:

cd $VIRTUAL_ENV
bin/nginx -p `pwd`/ -c ../test_project/etc/nginx.conf

create a wsgi.py file in project root:

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'test_project.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

get project on python path:

cd $HOME/webapps/teststack/venv/lib/python2.6/site-packages
ln -s $HOME/webapps/teststack/test_project .

startup uwsgi:

cd venv
bin/uwsgi -p 4 -s sock/uwsgi.sock -H `pwd`/ --pythonpath $HOME/webapps/teststack/test_project -w wsgi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment