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 = ( "" => "" )
#}

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

 

 

 

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