1 | #!/bin/bash |
---|
2 | # Autor: Nilton OS -- www.linuxpro.com.br |
---|
3 | echo 'setup-web2py-nginx-uwsgi-centos64.sh' |
---|
4 | echo 'Support CentOS 6.4' |
---|
5 | echo 'Installs Nginx 1.4.1 + uWSGI + Web2py' |
---|
6 | |
---|
7 | |
---|
8 | # Get Web2py Admin Password |
---|
9 | echo -e "Web2py Admin Password: \c " |
---|
10 | read PW |
---|
11 | |
---|
12 | echo -e "Set Server Name Ex: web2py.domain.com : \c " |
---|
13 | read SERVER_FQDN |
---|
14 | |
---|
15 | echo -e "Set Server IP: \c " |
---|
16 | read SERVER_IP |
---|
17 | |
---|
18 | |
---|
19 | echo "" >>/etc/hosts |
---|
20 | echo "$SERVER_IP $SERVER_FQDN" >>/etc/hosts |
---|
21 | |
---|
22 | yum update -y |
---|
23 | |
---|
24 | yum install -y http://mirror-fpt-telecom.fpt.net/fedora/epel/6/i386/epel-release-6-8.noarch.rpm |
---|
25 | yum clean all |
---|
26 | yum 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 |
---|
30 | yum install -y http://nginx.org/packages/rhel/6/i386/RPMS/nginx-1.4.1-1.el6.ngx.i386.rpm |
---|
31 | |
---|
32 | |
---|
33 | pip-python install --upgrade pip |
---|
34 | PIPPATH=`which pip` |
---|
35 | $PIPPATH install --upgrade uwsgi |
---|
36 | |
---|
37 | |
---|
38 | # Prepare folders for uwsgi |
---|
39 | mkdir /etc/uwsgi |
---|
40 | mkdir /var/log/uwsgi |
---|
41 | mkdir -p /var/www/ |
---|
42 | |
---|
43 | #usermod -a -G apache nginx |
---|
44 | mkdir -p /etc/nginx/ssl/ |
---|
45 | |
---|
46 | |
---|
47 | cd /etc/nginx/ssl |
---|
48 | openssl genrsa 1024 > web2py.key && chmod 400 web2py.key |
---|
49 | openssl req -new -x509 -nodes -sha1 -days 1780 -key web2py.key > web2py.crt |
---|
50 | openssl x509 -noout -fingerprint -text < web2py.crt > web2py.info |
---|
51 | |
---|
52 | |
---|
53 | echo '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 | } |
---|
73 | server { |
---|
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 | |
---|
102 | sed -i "s/YOUR_SERVER_IP/$SERVER_IP/" /etc/nginx/conf.d/web2py.conf |
---|
103 | sed -i "s/YOUR_SERVER_FQDN/$SERVER_FQDN/" /etc/nginx/conf.d/web2py.conf |
---|
104 | |
---|
105 | |
---|
106 | # Create configuration file /etc/uwsgi/web2py.ini |
---|
107 | echo '[uwsgi] |
---|
108 | |
---|
109 | socket = /var/www/web2py/logs/%n.socket |
---|
110 | pythonpath = /var/www/web2py/ |
---|
111 | mount = /=wsgihandler:application |
---|
112 | processes = 4 |
---|
113 | master = true |
---|
114 | harakiri = 60 |
---|
115 | reload-mercy = 8 |
---|
116 | cpu-affinity = 1 |
---|
117 | stats = /tmp/%n.stats.socket |
---|
118 | max-requests = 2000 |
---|
119 | limit-as = 512 |
---|
120 | reload-on-as = 256 |
---|
121 | reload-on-rss = 192 |
---|
122 | uid = nginx |
---|
123 | gid = nginx |
---|
124 | cron = 0 0 -1 -1 -1 python /var/www/web2py/web2py.py -Q -S welcome -M -R scripts/sessions2trash.py -A -o |
---|
125 | no-orphans = true |
---|
126 | chmod-socket = 666 |
---|
127 | ' >/etc/uwsgi/web2py.ini |
---|
128 | |
---|
129 | |
---|
130 | cd /var/www/ |
---|
131 | curl --progress -O http://web2py.com/examples/static/web2py_src.zip |
---|
132 | unzip web2py_src.zip && rm -rf web2py_src.zip |
---|
133 | # Download latest version of sessions2trash.py |
---|
134 | mv web2py/handlers/wsgihandler.py web2py/wsgihandler.py |
---|
135 | chown -R nginx:nginx web2py |
---|
136 | cd /var/www/web2py |
---|
137 | sudo -u nginx python -c "from gluon.main import save_password; save_password('$PW',443)" |
---|
138 | |
---|
139 | |
---|
140 | |
---|
141 | ## Daemons /start/stop |
---|
142 | |
---|
143 | echo '#!/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) |
---|
161 | UWSGI_BIN=`which uwsgi` |
---|
162 | test -x $UWSGI_BIN || { echo "$UWSGI_BIN not installed"; |
---|
163 | if [ "$1" = "stop" ]; then exit 0; |
---|
164 | else exit 5; fi; } |
---|
165 | |
---|
166 | UWSGI_EMPEROR_MODE=true |
---|
167 | UWSGI_VASSALS="/etc/uwsgi/" |
---|
168 | UWSGI_OPTIONS="--enable-threads --logto /var/log/uwsgi/uwsgi.log" |
---|
169 | lockfile=/var/lock/subsys/uwsgi |
---|
170 | |
---|
171 | UWSGI_OPTIONS="$UWSGI_OPTIONS --autoload" |
---|
172 | |
---|
173 | if [ "$UWSGI_EMPEROR_MODE" = "true" ] ; then |
---|
174 | UWSGI_OPTIONS="$UWSGI_OPTIONS --emperor $UWSGI_VASSALS" |
---|
175 | fi |
---|
176 | |
---|
177 | case "$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 | ;; |
---|
198 | esac |
---|
199 | exit 0 '> /etc/init.d/uwsgi |
---|
200 | |
---|
201 | chmod +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 |
---|
207 | chkconfig --del iptables |
---|
208 | |
---|
209 | chkconfig --levels 235 uwsgi on |
---|
210 | chkconfig --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 |
---|