RedHat 上安装 lighttpd 并配置 fastcgi + django 的记录
================== 安装 flup =================================
cd /downloads
mkdir flup
cd flup
svn co http://svn.saddi.com/flup/trunk
获取了 revision 2341.
cd trunk
python setup.py install
添加 manage.py 的执行权限
chmod +x /var/www/html/myproject/manage.py
启动 fastcgi
python /var/www/html/myproject/manage.py runfcgi method=prefork socket=/tmp/myproject.sock pidfile=/tmp/django.pid
================== 安装 lighttpd ==============================
首先要安装一些必要的库(否则后面会出错):
yum install glib2-devel
yum install pcre-devel
yum install zlib-devel
安装 lighttpd 1.4.13 版本
=============================
(开始尝试过 1.5.0,编译是没问题,但因为是一个 pre-release 版本,文档还没完全跟上。结果配置 fast-cgi / django 的时候有个选项不会配置,只好放弃。原因是新的配置语法用 mod_proxy_core 取代了 mod_fastcgi 等 3 个模块)
cd /downloads
wget http://www.lighttpd.net/assets/2007/1/29/lighttpd-1.4.13.tar.gz
tar zxvf lighttpd-1.4.13.tar.gz
cd lighttpd-1.4.13
./configure
make
make install
cd doc
cp lighttpd.conf /etc
vi /etc/lighttpd.conf
配置文件内容如下:
1 server.modules = ( 2 "mod_rewrite", 3 "mod_redirect", 4 "mod_alias", 5 "mod_access", 6 "mod_fastcgi", 7 "mod_accesslog" ) 8 9 server.document-root = "/var/www/html/" 10 server.errorlog = "/var/www/logs/lighttpd.error.log" 11 accesslog.filename = "/var/www/logs/access.log" 12 13 index-file.names = ( "index.php", "index.html", 14 "index.htm", "default.htm" ) 15 16 mimetype.assign = ( 17 ".pdf" => "application/pdf", 18 ".sig" => "application/pgp-signature", 19 ".spl" => "application/futuresplash", 20 ".class" => "application/octet-stream", 21 ".ps" => "application/postscript", 22 ".torrent" => "application/x-bittorrent", 23 ".dvi" => "application/x-dvi", 24 ".gz" => "application/x-gzip", 25 ".pac" => "application/x-ns-proxy-autoconfig", 26 ".swf" => "application/x-shockwave-flash", 27 ".tar.gz" => "application/x-tgz", 28 ".tgz" => "application/x-tgz", 29 ".tar" => "application/x-tar", 30 ".zip" => "application/zip", 31 ".mp3" => "audio/mpeg", 32 ".m3u" => "audio/x-mpegurl", 33 ".wma" => "audio/x-ms-wma", 34 ".wax" => "audio/x-ms-wax", 35 ".ogg" => "application/ogg", 36 ".wav" => "audio/x-wav", 37 ".gif" => "image/gif", 38 ".jpg" => "image/jpeg", 39 ".jpeg" => "image/jpeg", 40 ".png" => "image/png", 41 ".xbm" => "image/x-xbitmap", 42 ".xpm" => "image/x-xpixmap", 43 ".xwd" => "image/x-xwindowdump", 44 ".css" => "text/css", 45 ".html" => "text/html", 46 ".htm" => "text/html", 47 ".js" => "text/javascript", 48 ".asc" => "text/plain", 49 ".c" => "text/plain", 50 ".cpp" => "text/plain", 51 ".log" => "text/plain", 52 ".conf" => "text/plain", 53 ".text" => "text/plain", 54 ".txt" => "text/plain", 55 ".dtd" => "text/xml", 56 ".xml" => "text/xml", 57 ".mpeg" => "video/mpeg", 58 ".mpg" => "video/mpeg", 59 ".mov" => "video/quicktime", 60 ".qt" => "video/quicktime", 61 ".avi" => "video/x-msvideo", 62 ".asf" => "video/x-ms-asf", 63 ".asx" => "video/x-ms-asf", 64 ".wmv" => "video/x-ms-wmv", 65 ".bz2" => "application/x-bzip", 66 ".tbz" => "application/x-bzip-compressed-tar", 67 ".tar.bz2" => "application/x-bzip-compressed-tar" 68 ) 69 70 url.access-deny = ( "~", ".inc" ) 71 static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" ) 72 73 $HTTP["host"] == "www.mydomain.com" { 74 server.port = 80 75 url.redirect = ( 76 "^(.*)" => "http://mydomain.com:80$1" 77 ) 78 } 79 80 $HTTP["host"] == "mydomain.com" { 81 server.name = "mydomain.com" 82 server.port = 80 83 server.document-root = "/var/www/html/myproject" 84 85 fastcgi.server = ( 86 "/myproject.fcgi" => ( 87 "main" => ( 88 "socket" => "/tmp/myproject.sock", 89 "check-local" => "disable" 90 ) 91 ) 92 ) 93 alias.url = ( 94 "/site_media/" => "/var/www/html/myproject/media/", 95 ) 96 url.rewrite-once = ( 97 "(/site_media.*)$" => "$1", 98 "^(/.*)$" => "/myproject.fcgi$1" 99 ) 100 } 101 102
配置完毕后启动 lighttpd:
lighttpd -f /etc/lighttpd.conf
(如果不想运行为后台进程,用如下命令:
lighttpd -D -f /etc/lighttpd.conf
便于调试)
要停止 lighttpd 进程,用命令
ps -ef|grep lighttpd
查看到 pid
然后
kill -9 [pid]
即可。