1. Preparing the Environment
CentOs 6.3
Nginx-1.4.2.tar.gz http://nginx.org/download/nginx-1.4.2.tar.gz
Openssl-1.0.1c.tar.gz http://www.openssl.org/source/openssl-1.0.1c.tar.gz
Pcre-8.34.tar.gz ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz
Spawn-fcgi-1.6.4.tar.gz http://download.lighttpd.net/spawn-fcgi/releases-1.6.x/spawn-fcgi-1.6.4.tar.gz
Zlib-1.2.8.tar.gz http://zlib.net/zlib-1.2.8.tar.gz
Flup-1.0.2.tar.gz http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz
Yum Install GCC Make Yum Install GCC gcc-c++ python-setuptools python-pippip install web.py
2. Installation
2.1 Zlib Installation
tar zxvf zlib-1.2. 8. Tar . GZCD zlib-1.2. 8 . /Configuremake do install
2.2 Pcre Installation
tar zxvf pcre-8.34. Tar . GZCD pcre-8.34. /
Make Make Install
2.3 Nginx Installation
TarZXVF nginx-1.4.2.Tar. GZ CD Nginx-1.4.2./configure--sbin-path=/usr/local/nginx/Nginx--conf-path=/usr/local/nginx/nginx.conf--pid-path=/usr/local/nginx/Nginx.pid--with-Http_ssl_module--with-pcre=. /pcre-8.34--with-zlib=. /zlib-1.2.8--with-openssl=. /openssl-1.0. 1c Make&& Make Install
3. Test Nginx
Start:/usr/local/nginx/nginx
Visit: http://x.x.x.x
The following appears to indicate that the Nginx installation is normal
Temporarily close Nginx, the following is the shutdown Nginx script
#!/bin/SH# # Nginx-This script starts and stops the Nginx daemin # # Chkconfig:- - the# Description:nginx is an HTTP (s) server, HTTP (s) reverse \ # Proxy and IMAP/POP3 Proxy Server # processname:nginx # config:/usr/local/nginx/conf/nginx.conf # Pidfile:/usr/local/nginx/logs/Nginx.pid # SourcefunctionLibrary:/etc/rc.d/init.d/functions # Source Networking configuration:/etc/sysconfig/Network # Check that networking are up. [ "$NETWORKING"="No"] && exit0Nginx="/usr/local/nginx/nginx"Prog=$(basename$nginx) Nginx_conf_file="/usr/local/nginx/nginx.conf" Lockfile=/var/lock/subsys/nginx Start () {[-X $nginx] | | Exit5 [ -F $NGINX _conf_file] | | Exit6 Echo-N $"starting $prog:"Daemon $nginx-c $NGINX _conf_file retval=$?Echo[$retval-eq0] &&Touch$Lockfilereturn $retval} stop () {Echo-N $"stopping $prog:"Killproc $prog-QUIT retval=$?Echo[$retval-eq0] &&RM-F $Lockfilereturn $retval} restart () {configtest|| Return $?Stop Start} reload () {configtest|| Return $?Echo-N $"Reloading $prog:"Killproc $nginx-HUP RETVAL=$?Echo} force_reload () {restart} configtest () {$nginx-T-c $NGINX _conf_file} rh_status () {Status $prog} rh_status_q () {rh_status>/dev/NULL 2>&1 } Case " $" inchstart) Rh_status_q&& exit0 $1 ;; Stop) Rh_status_q|| Exit0 $1 ;; Restart|configtest) $1 ;; Reload) Rh_status_q|| Exit7 $1 ;; Force-reload) force_reload;; status) Rh_status;; Condrestart|try-restart) rh_status_q|| Exit0 ;; *) Echo$"Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"Exit2 Esac
4. Installation of fcgi and Flup
tar zxvf spawn-fcgi-1.6. 4. Tar . GZCD Spawn-fcgi-1.6. 4 . /Configuremake doinstall
tar zxvf flup-1.0. 2. Tar . GZCD Flup-1.0. 2 python setup.py Install
5. Configuring Nginx and Webpy applications
Vim/usr/local/nginx/nginx.conf
Worker_processes1; events {Worker_connections1024x768;} HTTP {include mime.types; Default_type Application/octet-stream; Sendfile on; Keepalive_timeout $; server {Listen the; server_name localhost; Root /data/www/; Access_log/data/log/Test.access.log; Location/{include fastcgi_params; Fastcgi_param script_filename $fastcgi _script_name; # [1] fastcgi_param path_info $fastcgi _script_name; # [2] Fastcgi_pass 127.0.0.1:9002; } location/static/{#配置静态文件路径访问 if (-F $request _filename) {rewrite ^/static/(. *) $/static/$1Break ; }} Error_page - 502 503 504/50x.html; Location= /50x.html {root html; } }}
The web.py app adds the following content server.py
if __name__ = = "__main__": Web.wsgi.runwsgi = lambda func, addr=none:web.wsgi.runfcgi (func, addr) App.run ()
Configure a startup script at the same time
[[email protected] www]# vim start. SH #!/bin/shspawn127.0. 0.1 9002
Start fcgi and Nginx
sh start. SH /etc/init.d/nginx start
Check the Listening port
[Email protected] www]# Netstat-nlpt |Egrep "9002|80"TCP0 0 127.0.0.1:9002 0.0.0.0:* LISTEN54799/python tcp0 0 0.0.0.0: the 0.0.0.0:* LISTEN54816/Nginx [[email protected] www]#
You can now enter http://x.x.x.x to access your app.
Webpy + nginx + fastcgi build Python app