I've been learning web2py on Webfaction off and on for a while now. The web2py install script on the Webfaction wiki is quite outdated and runs on an Apache instance that can barely stay within the default memory limits without serious tweaking. Responsiveness with web2py/apache out of the box with the default install script is unimpressive as well.
A while back I tried a lighttpd setup with web2py on Webfaction. The memory usage went way down and responsiveness was better but the web server was quite unstable. I found myself having to restart it constantly and I couldn't track down the cause of the breakages. After the host upped the default RAM limit on CentOS6 systems to 256MB things got better as it made Apache more manageable on custom installs but it still sucked overall. So I found the install script on the WF community support forum<http://community.webfaction.com/questions/7193/install-web2py-with-nginx-and-uwsgi>but it was horribly outdated and had multiple issues pointed out in the comments that went unfixed. I spent a couple hours today fixing the ignored errors, updating it to the latest nginx and uwsgi versions and fixing the errors which that brought on. After getting it working my RAM usage has decreased and responsiveness of my web2py apps has noticeably increased. I figured I'd share the script for anyone interested. I'm not a sysadmin, more of a hobbyist so any critique of my server configs here are greatly welcome. Please note that the comments are not mine. I merely updated the parts of the script that were required for it to work. All else was left as-is. Also, if anyone with knowledge of XML-RPC want's to make an actual Webfaction install script<https://docs.webfaction.com/xmlrpc-api/tutorial.html> for nginx/uwsgi/web2py that would be awesome. It could be added to the script wiki. #!/bin/sh # TODO's: # * find free port for communication for nginx and uwsgi # * test conjob creation properly echo 'Install script for nginx (1.2.6), uwsgi (1.4.3) and web2py (latest stable)' echo 'If you wish to create cronjobs comment out the last lines of this script' # port betweet nginx and uwsgi nginx_uwsgi_port=9001 # 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.2.6.tar.gz tar xvf nginx-1.2.6.tar.gz cd nginx-1.2.6 ./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.4.3.tar.gz tar xvf uwsgi-1.4.3.tar.gz cd uwsgi-1.4.3 make -f Makefile cp uwsgi ../../uwsgi/ cd ../../uwsgi echo "<uwsgi> <socket>127.0.0.1:${nginx_uwsgi_port}</socket> <workers>4</workers> <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> <master/> <memory-report/> </uwsgi>" > uwsgi.xml 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 - --