Skip to content

Instantly share code, notes, and snippets.

@HowardMei
Created April 2, 2012 06:51
Show Gist options
  • Save HowardMei/2281301 to your computer and use it in GitHub Desktop.
Save HowardMei/2281301 to your computer and use it in GitHub Desktop.
install web2py with nginx and uwsgi on webfaction
#!/bin/sh
# modified from: http://community.webfaction.com/questions/7193/install-web2py-with-nginx-and-uwsgi
# * bumped the versions of nginx, uwsgi and web2py
echo 'Install script for nginx-1.1.18 , uwsgi-1.1.2 and web2py-1.99.7 (latest stable)'
echo 'If you wish to create cronjobs comment out the last lines of this script'
# port betweet nginx and uwsgi, find a free port to use
nginx_uwsgi_port=9111
# Get web2py admin password
echo "Web2py admin password:"
read web2py_password
# Get webfaction application name
echo "Webfaction application name:"
read webfaction_app_name
# Get webfaction port number
echo "Webfaction application port:"
read webfaction_app_port
# port betweet nginx and uwsgi
echo "Port number for communication between nginx and uswgi (eg. 9001):"
read nginx_uwsgi_port
###
### web2py
###
cd ~/webapps/${webfaction_app_name}
wget http://www.web2py.com/examples/static/web2py_src.zip
unzip web2py_src.zip
rm web2py_src.zip
cd web2py
python -c "from gluon.main import save_password; save_password('${web2py_password}',${webfaction_app_port})"
cd ..
###
### nginx
###
mkdir downs
cd downs
# download and install nginx in the appname directory
wget http://nginx.org/download/nginx-1.1.18.tar.gz
tar xvf nginx-1.1.18.tar.gz
cd nginx-1.1.18
./configure \
--prefix=/home/${USER}/webapps/${webfaction_app_name}/nginx \
--sbin-path=/home/${USER}/webapps/${webfaction_app_name}/nginx/sbin/nginx \
--conf-path=/home/${USER}/webapps/${webfaction_app_name}/nginx/nginx.conf \
--error-log-path=/home/${USER}/webapps/${webfaction_app_name}/nginx/log/error.log \
--pid-path=/home/${USER}/webapps/${webfaction_app_name}/nginx/run/nginx.pid \
--lock-path=/home/${USER}/webapps/${webfaction_app_name}/nginx/lock/nginx.lock \
--with-http_gzip_static_module \
--http-log-path=/home/${USER}/webapps/${webfaction_app_name}/nginx/log/access.log \
--http-client-body-temp-path=/home/${USER}/webapps/${webfaction_app_name}/nginx/tmp/client/ \
--http-proxy-temp-path=/home/${USER}/webapps/${webfaction_app_name}/nginx/tmp/proxy/ \
--http-fastcgi-temp-path=/home/${USER}/webapps/${webfaction_app_name}/nginx/tmp/fcgi/
make && make install
cd ..
# configure nginx
cd ..
mkdir nginx/tmp
mkdir nginx/tmp/client
cd nginx
echo "
worker_processes 2;
events {
worker_connections 1024;
}
http {
access_log /home/${USER}/logs/user/access_appname.log combined;
error_log /home/${USER}/logs/user/error_appname.log crit;
include mime.types;
client_max_body_size 5m;
default_type application/octet-stream;
gzip_static on;
gzip_vary on;
sendfile on;
tcp_nodelay on;
server {
listen ${webfaction_app_port};
location ~* /(\w+)/static/ {
root /home/${USER}/webapps/${webfaction_app_name}/web2py/applications/;
}
location / {
uwsgi_pass 127.0.0.1:${nginx_uwsgi_port};
include uwsgi_params;
}
}
}
" > nginx.conf
echo "#!/bin/sh
kill -s QUIT \$( cat /home/${USER}/webapps/${webfaction_app_name}/nginx/run/nginx.pid )
" > stop
chmod +x stop
# start nginx
./sbin/nginx -c /home/${USER}/webapps/${webfaction_app_name}/nginx/nginx.conf
cd ..
###
### uwsgi
###
mkdir uwsgi
cd downs
# download and install uwsgi in the appname directory
wget http://projects.unbit.it/downloads/uwsgi-1.1.2.tar.gz
tar xvf uwsgi-1.1.2.tar.gz
cd uwsgi-1.1.2
make -f Makefile.Py27
cp uwsgi ../../uwsgi/
cd ../../uwsgi
echo "<uwsgi>
<socket>127.0.0.1:${nginx_uwsgi_port}</socket>
<master/>
<workers>4</workers>
<max-requests>1000</max-requests>
<no-orphans/>
<pythonpath>/home/${USER}/webapps/${webfaction_app_name}/web2py</pythonpath>
<pidfile>/home/${USER}/webapps/${webfaction_app_name}/uwsgi/uwsgi.pid</pidfile>
<daemonize>/home/${USER}/webapps/${webfaction_app_name}/uwsgi/uwsgi.log</daemonize>
<module>wsgihandler</module>
</uwsgi>" > uwsgi.xml
# export PYTHONPATH=${PYTHONPATH}:/home/${USER}/webapps/${webfaction_app_name}
# export PYTHONPATH=${PYTHONPATH}:/home/${USER}/webapps/${webfaction_app_name}/web2py
echo "#!/bin/sh
kill -s QUIT \$( cat /home/${USER}/webapps/${webfaction_app_name}/uwsgi/uwsgi.pid )
" > stop
chmod +x stop
# start uwsgi
./uwsgi -x /home/${USER}/webapps/${webfaction_app_name}/uwsgi/uwsgi.xml
cd ..
###
### cleanup
###
rm -rf downs
##
## create start/stop scripts
##
echo "#!/bin/sh
/home/${USER}/webapps/${webfaction_app_name}/nginx/sbin/nginx -c /home/${USER}/webapps/${webfaction_app_name}/nginx/nginx.conf
/home/${USER}/webapps/${webfaction_app_name}/uwsgi/uwsgi -x /home/${USER}/webapps/${webfaction_app_name}/uwsgi/uwsgi.xml
" > start
chmod +x start
echo "#!/bin/sh
kill -s QUIT \$( cat /home/${USER}/webapps/${webfaction_app_name}/uwsgi/uwsgi.pid )
kill -s QUIT \$( cat /home/${USER}/webapps/${webfaction_app_name}/nginx/run/nginx.pid )
" > stop
chmod +x stop
###
### create cronjobs
###
#nginx_cron="10,30,50 * * * * /home/${USER}/webapps/${webfaction_app_name}/nginx/sbin/nginx -c /home/${USER}/webapps/${webfaction_app_name}/nginx/nginx.conf"
#(crontab -l; echo "$nginx_cron" ) | crontab -
#
#uwsgi_cron="10,30,50 * * * * /home/${USER}/webapps/${webfaction_app_name}/uwsgi/uwsgi -x /home/${USER}/webapps/${webfaction_app_name}/uwsgi/uwsgi.xml"
#(crontab -l; echo "$uwsgi_cron" ) | crontab -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment