lighttpd使用

       之前在项目中使用的是thttpd,由于thttpd是用明文发送的,为了安全考虑,用https来代替http,增加了证书认证功能,所以最后选择了lighttpd。

      lighttpd支持了cgi和fcgi,thttpd只支持了cgi,为了兼容的同时避免重复开发,仅在lighttpd上配置了支持cgi功能。

      接下来简单了记录下自己的一些配置内容,后续有用到新功能再来添加。

      我是在buildroot将lighttpd库添加上,编译好之后会在/etc/lighttpd/ 目录下生成相应的一些配置档,如下图:

      

     

        lighttpd.conf是主要的配置档,modules.conf是新增模块的配置档,conf.d目录下有一些debug log以及对应模块的conf,每新增一个模块,在conf.d目录下都要有对应模块的conf,不然在启动时会报错。

     lighttpd的启动方式,install完成后会生成/etc/init.d/S50lighttpd 脚本,可以通过这个脚本来启动,通过以下指令来启动/停止。

     sh /etc/init.d/S50lighttpd start

     sh /etc/init.d/S50lighttpd stop

或者  /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf。

接下来就是根据实际情况来配置conf。

首先是ligthttpd.conf,主要修改

var.server_root = "/etc/network/thttpd"      //这是存放网页和cgi的路径

server.port = 443                                      //指定httpd在哪个端口号,如果为443,在访问时不需要指定port,否则就需要

                                                                 //http://192.168.203.1         http://192.168.203.1:80

#server.username  = "www-data"           //我把username和groupname注释了,我的网页是放在/etc目录下,使用www-data会没
#server.groupname = "www-data"         //权限访问,如果改成root会启动失败,注释后默认root启动lighttpd

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".scgi", ".sh", ".cgi")   //支持可执行文件的类型,将后缀名添加上

ssl.engine = "enable"                           //如果支持https,则需要添加上证书路径,访问时https://192.168.203.1:端口号
ssl.pemfile = "/etc/dongle/server.pem"

modules.conf

server.modules = (              //将需要添加的module添加上
  "mod_access",
#  "mod_alias",
#  "mod_auth",
#  "mod_authn_file",
#  "mod_evasive",
#  "mod_redirect",
#  "mod_rewrite",
#  "mod_setenv",
#  "mod_usertrack",
   "mod_openssl",
)

include "conf.d/cgi.conf"         //将要支持的模块包含conf档

所以接下来要添加conf.d目录下的conf

cgi.conf

#######################################################################
##
##  CGI modules
## --------------- 
##
## See https://redmine.lighttpd.net/projects/lighttpd/wiki/docs_modcgi
##
server.modules += ( "mod_cgi" )

##
## Plain old CGI handling
##
## For PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini.
##
cgi.assign                 = ( ".pl"  => "/usr/bin/perl",
                               ".cgi" => "",                  //指定为空
                               ".sh"  => "",                 //项目需要,支持.sh可执行文件
                               ".rb"  => "/usr/bin/ruby",
                               ".erb" => "/usr/bin/eruby",
                               ".py"  => "/usr/bin/python" )

##
## to get the old cgi-bin behavior of apache
##
## Note: make sure that mod_alias is loaded if you uncomment the
##       next line. (see modules.conf)
##
#alias.url += ( "/cgi-bin" => server_root + "/cgi-bin" )
#$HTTP["url"] =~ "^/cgi-bin" {
#   cgi.assign = ( "" => "" )
#}

##
#######################################################################
 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章