Skip to content

Commit

Permalink
Default nginx config for django, log folder and bare scripts for star…
Browse files Browse the repository at this point in the history
…tup.

Summary: Basic setup for nginx

Test Plan: run start and stop scripts and runserver in between.

Reviewers: bogdan2412

Reviewed By: bogdan2412

Differential Revision: http://phab.code4fun.de/D5
  • Loading branch information
bmatican committed Mar 5, 2013
1 parent 4c3e003 commit 456f929
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.swp
local_settings.py
db.sqlite3
.nginx_conf
66 changes: 66 additions & 0 deletions .nginx_conf_local
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
worker_processes 5;
worker_rlimit_nofile 8192;

events {
worker_connections 1024;
}

http {
# replace the following:
# $nginx_etc with /usr/local/etc/nginx for mac or /etc/nginx for linux
# set $project_name to the path to the project/app_name
# eg: /Users/Mati/mati/work/CodeStreak/CodeStreak;
include $nginx_etc/mime.types;
include $nginx_etc/proxy.conf;
default_type application/octet-stream;

sendfile on;
keepalive_timeout 65;

error_log /tmp/CodeStreak.nginx.log error;
log_format main
'$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';

upstream django {
server unix:///tmp/CodeStreak.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket
}

server {
root $project_name;

# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name 127.0.0.1 localhost;
charset utf-8;

#Max upload size
client_max_body_size 75M; # adjust to taste

location ~ ^/static/(.*)$ {
alias static_collected/$1;
expires 1d;
}

location ~ ^/media/(.*)$ {
alias media/$1;
expires 1d;
}

location ~ /favicon.ico {
alias static_collected/img/favicon.png;
expires 1d;
}

# Finally, send all non-media requests to the Django server.
location / {
# all proxy headers should have been set
uwsgi_pass django;
include $nginx_etc/uwsgi_params;
}
}
}
2 changes: 1 addition & 1 deletion CodeStreak/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding=utf8
# Django settings for CodeStreak project.

DEBUG = True
DEBUG = False
TEMPLATE_DEBUG = DEBUG

ADMINS = (
Expand Down
3 changes: 3 additions & 0 deletions CodeStreak/settings_debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from CodeStreak.settings import *
DEBUG = True
TEMPLATE_DEBUG = DEBUG
64 changes: 52 additions & 12 deletions runserver
Original file line number Diff line number Diff line change
@@ -1,22 +1,62 @@
# /bin/bash

MEMCACHED_PORT=11211
# just inc ase, we define base python here
if [ -z $PYTHON ];
then
PYTHON=python
fi

start_memcached()
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

start_uwsgi()
{
memcached -p $MEMCACHED_PORT &
MEMCACHED_PID=$!
echo "Starting memcached: pid=$MEMCACHED_PID"
echo "Starting uWSGI"
# TODO: fix permissions to 664, put user, nginx in same group and such..
uwsgi \
--socket /tmp/CodeStreak.sock \
--chmod-socket=666 \
--chdir $DIR \
--wsgi-file $DIR/CodeStreak/wsgi.py \
--master true \
--processes 10 \
--vacuum true \
$@
}

kill_memcached()
start_fcgi()
{
kill $MEMCACHED_PID
echo "Killing memcached: pid=$MEMCACHED_PID"
exit $?
echo "Starting FCGI"
$PYTHON manage.py runfcgi \
# method=prefork \
socket=/tmp/CodeStreak.socket \
# host=127.0.0.1 port=8080 \
settings=CodeStreak/settings_debug.py \
pidfile=/tmp/Codestreak.django.pid \
$@
}

# trap kill_memcached SIGINT
start_normal()
{
echo "Starting $PYTHON"
$PYTHON manage.py runserver $@
}

start_memcached
python manage.py runserver 0.0.0.0:8000
case $1 in
"--uwsgi")
shift
start_uwsgi $@
;;
"--fcgi")
shift
start_fcgi $@
;;
"--pypy")
PYTHON=pypy
shift
start_normal $@
;;
*)
PYTHON=python
start_normal $@
;;
esac
20 changes: 20 additions & 0 deletions start-nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

OS=$(uname -s)
case $OS in
"Darwin")
GROUP=www
;;
"Linux")
GROUP=www-data
;;
*)
echo "Unknown OS"
;;
esac

sudo nginx \
-c $DIR/.nginx_conf \
-g "pid /tmp/CodeStreak.nginx.pid; user $USER $GROUP;"
7 changes: 7 additions & 0 deletions stop-nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

sudo nginx \
-s stop \
-g "pid /tmp/CodeStreak.nginx.pid;"

0 comments on commit 456f929

Please sign in to comment.