It works !

<https://lh5.googleusercontent.com/-9MtuXR1IBAY/UQkeSt_pF9I/AAAAAAAAAE0/njp8fKPFoLA/s1600/web2pyOnNginx.jpg>

<modified script attached>

Here is the modified doc-string:

# Script for installing Web2py with Nginx and Uwsgi on Centos 6
> # Created By Hutchinson
> # Modified by spametki and then by Arnon Marcus
> # License: BSD
> # It was originally posted in this web2py-users group thread, for Centos 5:
> # https://groups.google.com/forum/?fromgroups#!topic/web2py/O4c4Jfr18tM
> # It was then talked about and converted to Centos 6 in this web2py-users 
> group thread:
> # https://groups.google.com/forum/?fromgroups#!topic/web2py/zUTIOABWbQI
> # It no longer requiers re-compilation/installation of a new python 
> version. 
> # Uwsgi is being compiled using the existing python version 2.6.6
> # that is already pre-installed in the os.


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


#!/bin/bash

# Script for installing Web2py with Nginx and Uwsgi on Centos 6
# Created By Hutchinson
# Modified by spametki and then by Arnon Marcus
# License: BSD

# It was originally posted in this web2py-users group thread, for Centos 5:
# https://groups.google.com/forum/?fromgroups#!topic/web2py/O4c4Jfr18tM

# It was then talked about and converted to Centos 6 in this web2py-users group thread:
# https://groups.google.com/forum/?fromgroups#!topic/web2py/zUTIOABWbQI

# It no longer requiers re-compilation/installation of a new python version. 
# Uwsgi is being compiled using the existing python version 2.6.6
# that is already pre-installed in the os.

# NOTE: The only thing that should need changing for
# each installation is the $BASEARCH (base architecture) of the machine.
# This is determined by doing uname -i. This is needed for the nginx installation.

# Retrieve base architecture
BASEARCH=$(uname -i)

# Get Web2py Admin Password
echo -e "Enter a password for web2py admin app: \c "
read  PW

echo 'Install development tools (it should take a while)'
yum install sudo unzip gcc gdbm-devel readline-devel ncurses-devel zlib-devel \
bzip2-devel sqlite-devel db4-devel openssl-devel tk-devel bluez-libs-devel \
make wget libxml2 libxml2-devel pcre pcre-devel autoconf automake python-devel python-setuptools

#=================================

# You can change uWSGI options
# to fit your deployment needs.
version=uwsgi-1.2.6

mkdir ~/src
chmod 777 ~/src
cd ~/src

echo 'Install uwsgi' $version
cd ~
curl -O http://projects.unbit.it/downloads/$version.tar.gz
tar zxvf $version.tar.gz
mkdir /opt/uwsgi-python
cp -R ./$version/* /opt/uwsgi-python
cd /opt/uwsgi-python

echo "build using the pre-existing python (2.6.6)"

python uwsgiconfig.py --build
useradd uwsgi

echo "Create and own uwsgi log"
# Note this log will need emptying from time to time

touch /var/log/uwsgi.log
chown uwsgi /var/log/uwsgi.log

echo "Install web2py"

cd /opt
mkdir ./web-apps
cd ./web-apps
curl -O http://www.web2py.com/examples/static/web2py_src.zip
unzip web2py_src.zip

echo "Set the ownership for web2py application to uwsgi"
chown -R uwsgi /opt/web-apps/web2py
cd /opt/web-apps/web2py
chmod -R u+rwx ./applications

echo "Now creating the admin password and creating the scaffolding app package"
sudo -u uwsgi python -c "from gluon.main import save_password;from gluon import widget;save_password('$PW',443);widget.console()"

echo "Now install nginx"
cd /etc/yum.repos.d
echo "[nginx]">nginx.repo

echo "baseurl=http://nginx.org/packages/centos/6/$BASEARCH/";>>nginx.repo
echo "gpgcheck=0">>nginx.repo
echo "enabled=1">>nginx.repo
yum install nginx

echo "We don't want the defaults, so remove them"
cd /etc/nginx/conf.d
mv default.conf default.conf.o
mv example_ssl.conf example_ssl.conf.o

echo "
The following configuration files are also needed
The options for uwsgi are in the following file.
Other options could be included.
"

echo "uwsgi_for_nginx.conf"

echo "
[uwsgi]
uuid=uwsgi
pythonpath = /opt/web-apps/web2py
module = wsgihandler
socket=127.0.0.1:9001
harakiri 60
harakiri-verbose
enable-threads
daemonize = /var/log/uwsgi.log
" > /opt/uwsgi-python/uwsgi_for_nginx.conf

chmod 755 /opt/uwsgi-python/uwsgi_for_nginx.conf

echo "
The next configuration file is for nginx, and goes in /etc/nginx/conf.d
It serves the static directory of applications directly. I have not set up
ssl because I access web2py admin by using ssh tunneling and the web2py rocket server.
It should be straightforward to set up the ssl server however.
"

echo "web2py.conf"

echo '
server {
  listen 80;
  server_name $hostname;
  location ~* /(\w+)/static/ {
    root /opt/web-apps/web2py/applications/;
  }
  location / {
    uwsgi_pass 127.0.0.1:9001;
    include uwsgi_params;
  }
}

server {
  listen 443;
  server_name $hostname;
  ssl on;
  ssl_certificate /etc/nginx/ssl/web2py.cert;
  ssl_certificate_key /etc/nginx/ssl/web2py.key;
  location / {
    uwsgi_pass 127.0.0.1:9001;
    include uwsgi_params;
    uwsgi_param UWSGI_SCHEME $scheme;
  }
}
' > /etc/nginx/conf.d/web2py.conf


echo "Auto-signed ssl certs"
mkdir /etc/nginx/ssl
echo "creating a self signed certificate"
echo "=================================="
openssl genrsa 1024 > /etc/nginx/ssl/web2py.key
chmod 400 /etc/nginx/ssl/web2py.key
openssl req -new -x509 -nodes -sha1 -days 365 -key /etc/nginx/ssl/web2py.key > /etc/nginx/ssl/web2py.cert
openssl x509 -noout -fingerprint -text < /etc/nginx/ssl/web2py.cert > /etc/nginx/ssl/web2py.info

echo "uwsgi as service"

echo '
#!/bin/bash

# uwsgi - Use uwsgi to run python and wsgi web apps.
#
# chkconfig: - 85 15
# description: Use uwsgi to run python and wsgi web apps.
# processname: uwsgi

# author: Roman Vasilyev

# Source function library.
. /etc/rc.d/init.d/functions

###########################
PATH=/opt/uwsgi-python:/sbin:/bin:/usr/sbin:/usr/bin
PYTHONPATH=/home/www-data/web2py
MODULE=wsgihandler
PROG=/opt/uwsgi-python/uwsgi
OWNER=uwsgi
NAME=uwsgi
DESC=uwsgi
DAEMON_OPTS="-s 127.0.0.1:9001 -M 4 -t 30 -A 4 -p 16 -b 32768 -d \
/var/log/$NAME.log --pidfile /var/run/$NAME.pid --uid $OWNER \
--ini-paste /opt/uwsgi-python/uwsgi_for_nginx.conf"
##############################

[ -f /etc/sysconfig/uwsgi ] && . /etc/sysconfig/uwsgi

lockfile=/var/lock/subsys/uwsgi

start () {
  echo -n "Starting $DESC: "
  daemon $PROG $DAEMON_OPTS
  retval=$?
  echo
  [ $retval -eq 0 ] && touch $lockfile
  return $retval
}

stop () {
  echo -n "Stopping $DESC: "
  killproc $PROG
  retval=$?
  echo
  [ $retval -eq 0 ] && rm -f $lockfile
  return $retval
}

reload () {
  echo "Reloading $NAME"
  killproc $PROG -HUP
  RETVAL=$?
  echo
}

restart () {
    stop
    start
}

rh_status () {
  status $PROG
}

rh_status_q() {
  rh_status >/dev/null 2>&1
}

case "$1" in
  start)
    rh_status_q && exit 0
    $1
    ;;
  stop)
    rh_status_q || exit 0
    $1
    ;;
  restart|force-reload)
    $1
    ;;
  reload)
    rh_status_q || exit 7
    $1
    ;;
  status)
    rh_status
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|reload|force-reload|status}" >&2
    exit 2
    ;;
  esac
  exit 0
' > /etc/init.d/uwsgi

chmod 755 /etc/init.d/uwsgi
chkconfig --add uwsgi
chkconfig uwsgi on

echo "
You can test it with

service uwsgi start

and stop it similarly.

Nginx has automatically been set up as a service
if you want to start it run

service nginx start

You should find the web2py welcome app will be displayed at your web address.
As they are both services, they should automatically start on a system reboot.
If you already had a server running, such as apache, you would need to stop
that and turn its service off before running nginx.
"

echo "Turning off apache service"

service httpd stop
chkconfig httpd off
cd ~

echo "
Installation complete. You might want to restart your server running

reboot

as superuser
"


Reply via email to