免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4506 | 回复: 4
打印 上一主题 下一主题

[Web] Fedora 8 上 lighttpd-1.4.20 的安装及使用 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-10-15 19:30 |只看该作者 |倒序浏览
参考: 加俊工作室 http://hi.baidu.com/iammonster/b ... 37f117738b6532.html

  Lighttpd是一个德国人领导的开源软件,其根本的目的是提供一个专门针对高性能网站,安全、快速、兼容性好并且灵活的web server环境。具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点。Lighttpd是众多OpenSource轻量级的web server中较为优秀的一个,支持FastCGI、CGI、Auth、输出压缩(output compress)、URL重写、Alias等重要功能。而Apache之所以流行,很大程度也是因为功能丰富,在lighttpd上很多功能都有相应的实现了,这点对于Apache的用户是非常重要的,因为迁移到lighttpd就必须面对这些问题。
  Lighttpd大约每6个月会出新的版本,截至到2008年9月30日,lighttpd的最新版本是1.4.20。
    本文记录了在Fedora 8上安装lighttpd-1.4.20的过程。

1)下载
   到官方网站上下载源码包lighttpd-1.4.20.tar.gz
      http://www.lighttpd.net/download

2)解压缩
      tar zxvf lighttpd-1.4.20.tar.gz
   得到目录lighttpd-1.4.20,进入该目录ls可以得到以下列表:
   aclocal.m4  config.guess  COPYING           INSTALL      missing     src
   AUTHORS     config.h.in   cygwin            install-sh   NEWS        tests
   autogen.sh  config.sub    depcomp           ltmain.sh    openwrt
   ChangeLog   configure     distribute.sh.in  Makefile.am  README
   compile     configure.in  doc               Makefile.in  SConstruct

3)查看配置选项
      ./configure --help
   可以得到配置选项列表,用户可以根据需要进行定制。这里使用缺省配置,那么缺省的安装目录为/usr/local

4)配置
      ./configure
   配置过程中出现错误:
       ...
      checking for pcre-config... no
      configure: error: pcre-config not found, install the pcre-devel package or build with --without-pcre
   google一下,原来pcre是Perl兼容的正规表达式库,其官方网站是http://www.pcre.org/,下载最新版本pcre-7.7.tar.bz2并安装:
      tar jxvf pcre-7.8.tar.bz2
      cd pcre-7.8
      ./configure        # 采用默认配置,使用./configure --help可以查看配置选项
      make
      su                 # 切换到根用户
      make install
   重新配置lighttpd,通过

5)编译并安装
      make
      su                 # 切换到根用户
      make install

6)启动
       在用户主目录下启动lighttpd start,结果显示"lighttpd: command not found"
       搜一下which lighttpd:
          /usr/bin/which: no lighttpd in (/usr/kerberos/bin:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/pFreeStyle/bin)
       那么lighttpd安装到哪里去了?原来lighttpd缺省安装到/usr/local/sbin目录下了,切换到/usr/local/sbin目录下尝试启动lighttpd:
           (server.c.54 No configuration available. Try using -f option.
       指示lighttpd启动需要指定配置文件

7)创建服务器所需文件和目录
       切换到源码包的根目录下,你会发现有一个doc目录,进入此目录:
         cd doc
         cp sysconfig.lighttpd /etc/sysconfig/lighttpd        # 需要根用户权限
       这个sysconfig.lighttpd文件有什么内容那,cat一下:
          LIGHTTPD_CONF_PATH=/etc/lighttpd/lighttpd.conf
       原来它指定了lighttpd配置文件的位置
          mkdir /etc/lighttpd                                 # 创建配置文件所在目录
          cp lighttpd.conf /etc/lighttpd/lighttpd.conf         # 使用缺省的配置文件
   好了,现在有了配置文件,切换到/usr/local/sbin目录下,尝试启动lighttpd:
      ./lighttpd -f /etc/lighttpd/lighttd.conf
      2008-10-15 18:22:35: (configfile.c.1164) base-docroot doesn't exist: /srv/www/htdocs/
      2008-10-15 18:22:35: (server.c.580) setting default values failed
   创建base-docroot目录,再尝试启动:
      ./lighttpd -f /etc/lighttpd/lighttpd.conf
      2008-10-15 18:25:55: (log.c.84) opening errorlog '/var/log/lighttpd/error.log' failed: No such file or directory
      2008-10-15 18:25:55: (server.c.88 Opening errorlog failed. Going down.
   创建/var/log/lighttpd/error.log文件,再启动,无错误信息,OK,PASS!

   到此,lighttpd安装成功。这就行了吗?如何访问那?那就需要配置lighttpd.conf配置文件了,这个文件很简单,根据注释就可以应付了。这里在/srv/www/htdocs/下加一个文件index.html:
       <html>
       <head>
       <title>
           Welcome to lighttpd!
       </title>
       </head>
       <body>
             @_@
       </body>
       </html>
   在浏览器中输入http://localhost,看到了什么@_@。缺省时lighttpd绑定server的所有接口,监听80端口,可以通过配置文件改动。

8)配置为系统服务
   每次要启动lighttpd而切换到/usr/local/sbin目录下并输入./lighttpd -f /etc/lighttpd/lighttpd.conf太麻烦了,而且一般使用的80端口的绑定还需要root权限,那就将它配置成系统服务吧。
   前面已经将lighttpd使用的配置文件复制到了/etc目录下,要将lighttpd作为系统服务启动还需要一个脚本,在源代码的doc目录下:rc.lighttpd和rc.lighttpd.redhat,前者适用于suse系统,而我用的是Fedora 8,所以使用了后一个脚本。
      cp rc.lighttpd.redhat /etc/init.d/lighttpd
      cd /etc/init.d/
      cat lighttpd   =>   lighttpd="/usr/sbin/lighttpd"
                      修改为  lighttpd="/usr/local/sbin/lighttpd"
   希望服务器启动的时候就启动lighttpd:
       chkconfig lighttpd on  
   以后使用时直接使用service lighttpd [command]就可以了,可用的命令有[start|stop|restart|condrestart|reload|status]和

[ 本帖最后由 pFreeStyle 于 2008-10-18 09:20 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-10-15 22:54 |只看该作者
不知性能和配置难度方面如何?

论坛徽章:
0
3 [报告]
发表于 2008-10-16 08:17 |只看该作者

回复 #2 jerrywjl 的帖子

刚接触,就想趁它代码量不是太大,好好研究一下

性能没有比较过,但是配置应该不难,它的配置文件还是比较短小的
编译时支持哪些功能可以通过./configure --help来查看


补充一下:http://redmine.lighttpd.net/wiki/lighttpd/Page_index/special

[ 本帖最后由 pFreeStyle 于 2008-10-16 09:33 编辑 ]

论坛徽章:
0
4 [报告]
发表于 2008-10-16 09:50 |只看该作者

配置lighttpd-1.4.20支持CGI

参考:http://www.xianguo.com/go.php?fi=274610229

    前面安装了lighttpd-1.4.20,并且成功测试了静态页面,下面尝试访问perl写CGI。这里不描述CGI脚本的详细内容,
主要是讲如何配置lighttpd-1.4.20支持CGI。
    写一个简单的CGI脚本,然后通过浏览器访问,结果显示“403 - Forbidden”禁止访问?到官方网站上查找
http://redmine.lighttpd.net/wiki ... entlyAskedQuestions下有这样一段描述

Why do I still get a 403 status, even though the permissions on my doc root directory and its contents are set to 755?¶

Nine times out of ten (in IRC support), you have forgotten to check the permissions on one of the parent directories. Double check each directory in your path to insure the lighttpd user can access the nested doc root.

又仔细检测一下,发现目录访问权限没有问题

    google一下,原来是配置文件里没有启动CGI支持,这里显示修改的内容:
        server.modules += ("mod_cgi")
修改配置文件后重新启动:service lighttpd restart。重新访问,还是“403 - Forbidden”。
    继续查看配置文件
    #### CGI module
    #cgi.assign                 = ( ".pl"  => "/usr/bin/perl",
    #                              ".cgi" => "/usr/bin/perl" )
原来前面启动了CGI支持,但是脚本的执行也需要指定可以使用的解释器。改为:
    #### CGI module
    cgi.assign                 = ( ".pl"  => "/usr/bin/perl",
                                  ".cgi" => "/usr/bin/perl" )
再次重新启动,访问成功^^

论坛徽章:
0
5 [报告]
发表于 2008-10-18 09:19 |只看该作者

使用CGI时遇到的一个问题

若是从页面中调用cgi,例如form表单,则可以直接使用cgi脚本,不需要后缀名
    若是需要直接从浏览器中访问脚本,则脚本需要指定扩展名,例如hello.cgi。这是因为lighttpd配置文件static-file.exclude-extensions字段指定支持的脚本后缀名,若是没有则直接访问时会让你保存请求的脚本。
    好像不是很方便:(
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP