Merge pull request #1258 from torchbox/feature/sample-configs

Add sample uwsgi and nginx configuration files
pull/1501/head
Matt Westcott 2015-07-09 17:34:36 +01:00
commit c083344785
4 zmienionych plików z 150 dodań i 250 usunięć

Wyświetl plik

@ -0,0 +1,52 @@
# vim:sw=4 ts=4 et:
#
# This is a sample nginx configuration for a Wagtail application running under
# uWSGI.
server {
# We don't set 'root' here, because we send location / to uWSGI, so
# nothing ends up at nginx's default handler.
listen 80;
server_name mywagtail.org;
error_log /var/log/nginx/mywagtail.org_error.log;
access_log /var/log/nginx/mywagtail.org_access.log;
# Maximum file upload size.
client_max_body_size 64M;
# Enable content compression for text types.
gzip on;
gzip_types text/plain text/css application/x-javascript image/svg+xml;
gzip_comp_level 1;
gzip_disable msie6;
gzip_http_version 1.0;
gzip_proxied any;
gzip_vary on;
location /static/ {
access_log off;
expires 3600;
alias /home/mywagtail/app/static/;
}
# Set a longer expiry for CACHE/, because the filenames are unique.
location /static/CACHE/ {
access_log off;
expires 864000;
alias /home/mywagtail/static/CACHE/;
}
# Only server /media/images by default, not e.g. original_images/.
location /media/images {
expires 864000;
alias /home/mywagtail/app/media/;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/home/mywagtail/mywagtail.sock;
break;
}
}

Wyświetl plik

@ -0,0 +1,98 @@
# vim:sw=4 ts=4 et:
#
# This is a sample uWSGI configuration file for running a Wagtail application.
# It's designed to run under uWSGI's Emperor mode[0], but should work fine as
# a standalone instance, e.g. under supervisord using
# 'uwsgi --ini /path/to/wagtail.ini'.
#
# This configuration assumes an application called 'mywagtail', running under
# the 'mywagtail' user account, with the application deployed in
# /home/mywagtail/app and the virtualenv in /home/mywagtail/venv.
#
# [0] http://uwsgi-docs.readthedocs.org/en/latest/Emperor.html
[uwsgi]
# Abort on unknown configuration options.
strict = true
uid = mywagtail
gid = mywagtail
umask = 022
# Report memory usage to check for leaks; optional.
memory-report = true
# Change these paths to where uWSGI is installed on your system. If you've
# installed uWSGI with pip, then you won't have any plugins, so plugin-dir
# can be omitted.
binary-path = /opt/tbx/bin/uwsgi
plugin-dir = /opt/tbx/lib/uwsgi/plugins
# Shut down worker processes when we exit.
no-orphans = true
# Provide a statistics socket for uwsgitop; optional.
stats = /home/mywagtail/mywagtail.stats
# Run in master mode.
master = true
# Set this to the root directory of your project.
chdir = /home/mywagtail/app
# ... and its virtualenv.
virtualenv = /home/mywagtail/venv
# Create a UNIX socket that the web server can access. Replace 'www-data'
# with the group (not the user) that your web server runs as.
#
# To use FastCGI instead of the uWSGI protocol, replace 'uwsgi-socket' with
# 'fastcgi-socket'.
uwsgi-socket = /home/mywagtail/mywagtail.sock
chmod-socket = 660
chown-socket = mywagtail:www-data
# The number of worker processes to create.
workers = 5
# Create multiple threads per worker. This is more memory-efficient if your
# application is thread-safe.
enable-threads = true
threads = 5
# Use cheaper to kill off idle workers. This doesn't always work well; for
# example, on Debian 7 with recently uWSGI versions it appears to sometimes
# deadlock the application when killing a worker. If this isn't specified,
# uWSGI will just create the maximum number of workers at all times.
cheaper-algo = spare
cheaper = 1
cheaper-initial = 1
cheaper-step = 1
# Application environment.
env = PATH=/home/mywagtail/venv/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
env = HOME=/home/mywagtail
# Set $PYTHONPATH so that 'django-admin.py' worker without needing the
# virtualenv active.
env = PYTHONPATH=/home/mywagtail/app/mywagtail
# Settings module.
env = DJANGO_SETTINGS_MODULE=myapp.settings.production
# WSGI application. Wagtail includes this in the default template.
module = mywagtail.wsgi:application
# You can run addational daemons along with the application; for example,
# if you want to run Celery:
attach-daemon = celery worker -A myceleryapp -C -c1
attach-daemon = celery beat -A myceleryapp -C
# Log errors and requests.
logto = /var/log/uwsgi/mywagtail.log
log-date = true
log-prefix = [mywagtail]
logfile-chown = true
# Enable thunder lock to prevent the thundering herd problem.
thunder-lock = true
pcre-jit = true
close-on-exec = true
buffer-size = 16384

Wyświetl plik

@ -1,125 +0,0 @@
#!/usr/bin/env bash
# Production-configured Wagtail installation.
# BUT, SECURE SERVICES/ACCOUNT FOR FULL PRODUCTION USE!
# For a non-dummy email backend configure Django's EMAIL_BACKEND
# in settings/production.py post-installation.
# Tested on Debian 7.0.
# Tom Dyson and Neal Todd
# NB: Ensure the system locale is okay before running (dpkg-reconfigure locales).
PROJECT=mywagtail
PROJECT_ROOT=/usr/local/django
echo "This script overwrites key files, and should only be run on a new box."
read -p "Type 'yes' to confirm: " CONFIRM
[ "$CONFIRM" == "yes" ] || exit
read -p "Enter a name for your project [$PROJECT]: " U_PROJECT
if [ ! -z "$U_PROJECT" ]; then
PROJECT=$U_PROJECT
fi
read -p "Enter the root of your project, without trailing slash [$PROJECT_ROOT]: " U_PROJECT_ROOT
if [ ! -z "$U_PROJECT_ROOT" ]; then
PROJECT_ROOT=$U_PROJECT_ROOT
fi
if [ ! -z "$PROJECT_ROOT" ]; then
mkdir -p $PROJECT_ROOT || exit
fi
echo -e "\nPlease come back in a few minutes, when we'll need you to create an admin account."
sleep 5
SERVER_IP=`ifconfig eth0 |grep "inet addr" | cut -d: -f2 | cut -d" " -f1`
aptitude update
aptitude -y install git python-pip nginx postgresql redis-server
aptitude -y install postgresql-server-dev-all python-dev libjpeg62-dev
perl -pi -e "s/^(local\s+all\s+postgres\s+)peer$/\1trust/" /etc/postgresql/9.1/main/pg_hba.conf
service postgresql reload
aptitude -y install openjdk-7-jre-headless
curl -O https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.0.0.deb
dpkg -i elasticsearch-1.0.0.deb
rm elasticsearch-1.0.0.deb
perl -pi -e"s/# network.host: 192.168.0.1/network.host: 127.0.0.1/" /etc/elasticsearch/elasticsearch.yml
update-rc.d elasticsearch defaults 95 10
service elasticsearch start
cd $PROJECT_ROOT
git clone https://github.com/torchbox/wagtaildemo.git $PROJECT
cd $PROJECT
mv wagtaildemo $PROJECT
perl -pi -e"s/wagtaildemo/$PROJECT/" manage.py $PROJECT/wsgi.py $PROJECT/settings/*.py
rm -r etc README.md Vagrantfile* .git .gitignore
dd if=/dev/zero of=/tmpswap bs=1024 count=524288
mkswap /tmpswap
swapon /tmpswap
pip install -r requirements/production.txt
swapoff -v /tmpswap
rm /tmpswap
echo SECRET_KEY = \"`python -c 'import random; print "".join([random.SystemRandom().choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for i in range(50)])'`\" > $PROJECT/settings/local.py
echo ALLOWED_HOSTS = [\'$SERVER_IP\',] >> $PROJECT/settings/local.py
createdb -Upostgres $PROJECT
./manage.py syncdb --settings=$PROJECT.settings.production
./manage.py migrate --settings=$PROJECT.settings.production
./manage.py update_index --settings=$PROJECT.settings.production
./manage.py collectstatic --settings=$PROJECT.settings.production --noinput
pip install uwsgi
cp $PROJECT/wsgi.py $PROJECT/wsgi_production.py
perl -pi -e"s/($PROJECT.settings)/\1.production/" $PROJECT/wsgi_production.py
curl -O https://raw.githubusercontent.com/nginx/nginx/master/conf/uwsgi_params
cat << EOF > /etc/nginx/sites-enabled/default
upstream django {
server unix://$PROJECT_ROOT/$PROJECT/uwsgi.sock;
}
server {
listen 80;
charset utf-8;
client_max_body_size 75M; # max upload size
location /media {
alias $PROJECT_ROOT/$PROJECT/media;
}
location /static {
alias $PROJECT_ROOT/$PROJECT/static;
}
location / {
uwsgi_pass django;
include $PROJECT_ROOT/$PROJECT/uwsgi_params;
}
}
EOF
cat << EOF > $PROJECT_ROOT/$PROJECT/uwsgi_conf.ini
[uwsgi]
chdir = $PROJECT_ROOT/$PROJECT
module = $PROJECT.wsgi_production
master = true
processes = 10
socket = $PROJECT_ROOT/$PROJECT/uwsgi.sock
chmod-socket = 666
vacuum = true
EOF
mkdir -p /etc/uwsgi/vassals/
ln -s $PROJECT_ROOT/$PROJECT/uwsgi_conf.ini /etc/uwsgi/vassals/
curl -o /etc/init.d/uwsgi https://raw.githubusercontent.com/torchbox/wagtail/master/scripts/install/uwsgi-init.d
mkdir /var/log/uwsgi
chmod 755 /etc/init.d/uwsgi
update-rc.d uwsgi defaults
service uwsgi start
service nginx restart
URL="http://$SERVER_IP"
echo -e "\n\nWagtail lives!\n\n"
echo "The public site is at $URL/"
echo "and the admin interface is at $URL/admin/"

Wyświetl plik

@ -1,125 +0,0 @@
#!/usr/bin/env bash
# Production-configured Wagtail installation.
# BUT, SECURE SERVICES/ACCOUNT FOR FULL PRODUCTION USE!
# For a non-dummy email backend configure Django's EMAIL_BACKEND
# in settings/production.py post-installation.
# Tested on Ubuntu 13.04 and 13.10.
# Tom Dyson and Neal Todd
PROJECT=mywagtail
PROJECT_ROOT=/usr/local/django
echo "This script overwrites key files, and should only be run on a new box."
read -p "Type 'yes' to confirm: " CONFIRM
[ "$CONFIRM" == "yes" ] || exit
read -p "Enter a name for your project [$PROJECT]: " U_PROJECT
if [ ! -z "$U_PROJECT" ]; then
PROJECT=$U_PROJECT
fi
read -p "Enter the root of your project, without trailing slash [$PROJECT_ROOT]: " U_PROJECT_ROOT
if [ ! -z "$U_PROJECT_ROOT" ]; then
PROJECT_ROOT=$U_PROJECT_ROOT
fi
if [ ! -z "$PROJECT_ROOT" ]; then
mkdir -p $PROJECT_ROOT || exit
fi
echo -e "\nPlease come back in a few minutes, when we'll need you to create an admin account."
sleep 5
SERVER_IP=`ifconfig eth0 |grep "inet addr" | cut -d: -f2 | cut -d" " -f1`
aptitude update
aptitude -y install git python-pip nginx postgresql redis-server
aptitude -y install postgresql-server-dev-all python-dev libjpeg62-dev
perl -pi -e "s/^(local\s+all\s+postgres\s+)peer$/\1trust/" /etc/postgresql/9.3/main/pg_hba.conf
service postgresql reload
aptitude -y install openjdk-7-jre-headless
curl -O https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.0.0.deb
dpkg -i elasticsearch-1.0.0.deb
rm elasticsearch-1.0.0.deb
perl -pi -e"s/# network.host: 192.168.0.1/network.host: 127.0.0.1/" /etc/elasticsearch/elasticsearch.yml
update-rc.d elasticsearch defaults 95 10
service elasticsearch start
cd $PROJECT_ROOT
git clone https://github.com/torchbox/wagtaildemo.git $PROJECT
cd $PROJECT
mv wagtaildemo $PROJECT
perl -pi -e"s/wagtaildemo/$PROJECT/" manage.py $PROJECT/wsgi.py $PROJECT/settings/*.py
rm -r etc README.md Vagrantfile* .git .gitignore
dd if=/dev/zero of=/tmpswap bs=1024 count=524288
mkswap /tmpswap
swapon /tmpswap
pip install -r requirements/production.txt
swapoff -v /tmpswap
rm /tmpswap
echo SECRET_KEY = \"`python -c 'import random; print "".join([random.SystemRandom().choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for i in range(50)])'`\" > $PROJECT/settings/local.py
echo ALLOWED_HOSTS = [\'$SERVER_IP\',] >> $PROJECT/settings/local.py
createdb -Upostgres $PROJECT
./manage.py syncdb --settings=$PROJECT.settings.production
./manage.py migrate --settings=$PROJECT.settings.production
./manage.py update_index --settings=$PROJECT.settings.production
./manage.py collectstatic --settings=$PROJECT.settings.production --noinput
pip install uwsgi
cp $PROJECT/wsgi.py $PROJECT/wsgi_production.py
perl -pi -e"s/($PROJECT.settings)/\1.production/" $PROJECT/wsgi_production.py
curl -O https://raw.githubusercontent.com/nginx/nginx/master/conf/uwsgi_params
cat << EOF > /etc/nginx/sites-enabled/default
upstream django {
server unix://$PROJECT_ROOT/$PROJECT/uwsgi.sock;
}
server {
listen 80;
charset utf-8;
client_max_body_size 75M; # max upload size
location /media {
alias $PROJECT_ROOT/$PROJECT/media;
}
location /static {
alias $PROJECT_ROOT/$PROJECT/static;
}
location / {
uwsgi_pass django;
include $PROJECT_ROOT/$PROJECT/uwsgi_params;
}
}
EOF
cat << EOF > $PROJECT_ROOT/$PROJECT/uwsgi_conf.ini
[uwsgi]
chdir = $PROJECT_ROOT/$PROJECT
module = $PROJECT.wsgi_production
master = true
processes = 10
socket = $PROJECT_ROOT/$PROJECT/uwsgi.sock
chmod-socket = 666
vacuum = true
EOF
mkdir -p /etc/uwsgi/vassals/
ln -s $PROJECT_ROOT/$PROJECT/uwsgi_conf.ini /etc/uwsgi/vassals/
cat << EOF > /etc/init/uwsgi.conf
description "uwsgi for wagtail"
start on runlevel [2345]
stop on runlevel [06]
exec uwsgi --emperor /etc/uwsgi/vassals
EOF
service uwsgi start
service nginx restart
URL="http://$SERVER_IP"
echo -e "\n\nWagtail lives!\n\n"
echo "The public site is at $URL/"
echo "and the admin interface is at $URL/admin/"