source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/scripts/setup-web2py-nginx-uwsgi-centos64.sh @ 42095c5

mainqndtest v1.1.1
Last change on this file since 42095c5 was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 5.9 KB
Line 
1#!/bin/bash
2# Autor: Nilton OS -- www.linuxpro.com.br
3echo 'setup-web2py-nginx-uwsgi-centos64.sh'
4echo 'Support CentOS  6.4'
5echo 'Installs Nginx 1.4.1 + uWSGI + Web2py'
6
7
8# Get Web2py Admin Password
9echo -e "Web2py Admin Password: \c "
10read  PW
11
12echo -e "Set Server Name Ex: web2py.domain.com : \c "
13read  SERVER_FQDN
14
15echo -e "Set Server IP: \c "
16read  SERVER_IP
17
18
19echo "" >>/etc/hosts
20echo "$SERVER_IP  $SERVER_FQDN" >>/etc/hosts
21
22yum update -y
23
24yum install -y http://mirror-fpt-telecom.fpt.net/fedora/epel/6/i386/epel-release-6-8.noarch.rpm
25yum clean all
26yum install -y gcc libxml2-devel python-devel python-pip PyXML unzip make sudo
27
28## 64Bits System
29## yum install -y http://nginx.org/packages/rhel/6/x86_64/RPMS/nginx-1.4.1-1.el6.ngx.x86_64.rpm
30yum install -y http://nginx.org/packages/rhel/6/i386/RPMS/nginx-1.4.1-1.el6.ngx.i386.rpm
31
32
33pip-python install --upgrade pip
34PIPPATH=`which pip`
35$PIPPATH install --upgrade uwsgi
36
37
38# Prepare folders for uwsgi
39mkdir /etc/uwsgi
40mkdir /var/log/uwsgi
41mkdir -p /var/www/
42
43#usermod -a -G apache nginx
44mkdir -p /etc/nginx/ssl/
45
46
47cd /etc/nginx/ssl
48openssl genrsa 1024 > web2py.key && chmod 400 web2py.key
49openssl req -new -x509 -nodes -sha1 -days 1780 -key web2py.key > web2py.crt
50openssl x509 -noout -fingerprint -text < web2py.crt > web2py.info
51
52
53echo 'server {
54        listen          YOUR_SERVER_IP:80;
55        server_name     YOUR_SERVER_FQDN;
56        #to enable correct use of response.static_version
57        location ~* /(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$ {
58            alias /var/www/web2py/applications/$1/static/$2;
59            expires max;
60        }
61        location / {
62            #uwsgi_pass      127.0.0.1:9001;
63            uwsgi_pass      unix:///var/www/web2py/logs/web2py.socket;
64            include         /etc/nginx/uwsgi_params;
65            uwsgi_param     UWSGI_SCHEME $scheme;
66            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
67
68            ### remove the comments if you use uploads (max 10 MB)
69            #client_max_body_size 10m;
70            ###
71        }
72}
73server {
74        listen YOUR_SERVER_IP:443 default_server ssl;
75        server_name     YOUR_SERVER_FQDN;
76        ssl_certificate         /etc/nginx/ssl/web2py.crt;
77        ssl_certificate_key     /etc/nginx/ssl/web2py.key;
78        ssl_prefer_server_ciphers on;
79        ssl_session_cache shared:SSL:10m;
80        ssl_session_timeout 10m;
81        ssl_ciphers ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA;
82        ssl_protocols SSLv3 TLSv1;
83        keepalive_timeout    70;
84        location ~* /(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$ {
85            alias /var/www/web2py/applications/$1/static/$2;
86            expires max;
87        }
88        location / {
89            #uwsgi_pass      127.0.0.1:9001;
90            uwsgi_pass      unix:///var/www/web2py/logs/web2py.socket;
91            include         /etc/nginx/uwsgi_params;
92            uwsgi_param     UWSGI_SCHEME $scheme;
93            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
94
95            ### remove the comments if you use uploads (max 10 MB)
96            #client_max_body_size 10m;
97            ###
98        }
99
100}' >/etc/nginx/conf.d/web2py.conf
101
102sed -i "s/YOUR_SERVER_IP/$SERVER_IP/" /etc/nginx/conf.d/web2py.conf
103sed -i "s/YOUR_SERVER_FQDN/$SERVER_FQDN/" /etc/nginx/conf.d/web2py.conf
104
105
106# Create configuration file /etc/uwsgi/web2py.ini
107echo '[uwsgi]
108
109socket = /var/www/web2py/logs/%n.socket
110pythonpath = /var/www/web2py/
111mount = /=wsgihandler:application
112processes = 4
113master = true
114harakiri = 60
115reload-mercy = 8
116cpu-affinity = 1
117stats = /tmp/%n.stats.socket
118max-requests = 2000
119limit-as = 512
120reload-on-as = 256
121reload-on-rss = 192
122uid = nginx
123gid = nginx
124cron = 0 0 -1 -1 -1 python /var/www/web2py/web2py.py -Q -S welcome -M -R scripts/sessions2trash.py -A -o
125no-orphans = true
126chmod-socket = 666
127' >/etc/uwsgi/web2py.ini
128
129
130cd /var/www/
131curl --progress -O http://web2py.com/examples/static/web2py_src.zip
132unzip web2py_src.zip && rm -rf web2py_src.zip
133# Download latest version of sessions2trash.py
134mv web2py/handlers/wsgihandler.py web2py/wsgihandler.py
135chown -R nginx:nginx web2py
136cd /var/www/web2py
137sudo -u nginx python -c "from gluon.main import save_password; save_password('$PW',443)"
138
139
140
141## Daemons /start/stop
142
143echo '#!/bin/sh
144# Autor: Nilton OS -- www.linuxpro.com.br
145#
146#
147### BEGIN INIT INFO
148# Provides:          uwsgi
149# Required-Start:    $syslog $remote_fs
150# Should-Start:      $time ypbind smtp
151# Required-Stop:     $syslog $remote_fs
152# Should-Stop:       ypbind smtp
153# Default-Start:     3 5
154# Default-Stop:      0 1 2 6
155### END INIT INFO
156
157# Source function library.
158. /etc/rc.d/init.d/functions
159
160# Check for missing binaries (stale symlinks should not happen)
161UWSGI_BIN=`which uwsgi`
162test -x $UWSGI_BIN || { echo "$UWSGI_BIN not installed";
163        if [ "$1" = "stop" ]; then exit 0;
164        else exit 5; fi; }
165
166UWSGI_EMPEROR_MODE=true
167UWSGI_VASSALS="/etc/uwsgi/"
168UWSGI_OPTIONS="--enable-threads --logto /var/log/uwsgi/uwsgi.log"
169lockfile=/var/lock/subsys/uwsgi
170
171UWSGI_OPTIONS="$UWSGI_OPTIONS --autoload"
172
173if [ "$UWSGI_EMPEROR_MODE" = "true" ] ; then
174    UWSGI_OPTIONS="$UWSGI_OPTIONS --emperor $UWSGI_VASSALS"
175fi
176
177case "$1" in
178    start)
179        echo -n "Starting uWSGI "
180        daemon $UWSGI_BIN $UWSGI_OPTIONS &
181        ;;
182    stop)
183        echo -n "Shutting down uWSGI "
184        killproc $UWSGI_BIN
185        ;;
186    restart)
187        $0 stop
188        $0 start
189        ;;
190    status)
191        echo -n "Checking for service uWSGI "
192        status $UWSGI_BIN
193        ;;
194    *)
195        echo "Usage: $0 {start|stop|status|restart}"
196        exit 1
197        ;;
198esac
199exit 0 '> /etc/init.d/uwsgi
200
201chmod +x /etc/init.d/uwsgi
202
203/etc/init.d/uwsgi start
204/etc/init.d/nginx start
205
206/etc/init.d/iptables stop
207chkconfig --del iptables
208
209chkconfig --levels 235 uwsgi on
210chkconfig --levels 235 nginx on
211
212## you can reload uwsgi with
213#/etc/init.d/uwsgi restart
214## to reload web2py only (without restarting uwsgi)
215# touch /etc/uwsgi/web2py.ini
Note: See TracBrowser for help on using the repository browser.