1. 程式人生 > >我的openwrt學習筆記(二十八)webserver之lighttpd

我的openwrt學習筆記(二十八)webserver之lighttpd

Lighttpd是一個德國人領導的開源軟體,其根本的目的是提供一個專門針對高效能網站,安全、快速、相容性好並且靈活的web server環境。具有非常低的記憶體開銷,cpu佔用率低,效能好,以及豐富的模組等特點。
lighttpd 是眾多OpenSource輕量級的web server中較為優秀的一個。支援FastCGI, CGI, Auth, 輸出壓縮(output compress), URL重寫, Alias等重要功能,而Apache之所以流行,很大程度也是因為功能豐富,在lighttpd上很多功能都有相應的實現了,這點對於apache的使用者是非常重要的,因為遷移到lighttpd就必須面對這些問題。
實用起來lighttpd確實非常不錯,apache主要的問題是密集併發下,不斷的fork()和切換,以及較高(相對於 lighttpd而言)的記憶體佔用,使系統的資源幾盡枯竭。而lighttpd採用了Multiplex技術,程式碼經過優化,體積非常小,資源佔用很低,而且反應速度相當快。
利用apache的rewrite技術,將繁重的cgi/fastcgi任務交給lighttpd來完成,充分利用兩者的優點,現在那臺伺服器的負載下降了一個數量級,而且反應速度也提高了一個甚至是2個數量級!
lighttpd 適合靜態資源類的服務,比如圖片、資原始檔、靜態HTML等等的應用,效能應該比較好,同時也適合簡單的CGI應用的場合。
官方地址:

http://www.lighttpd.net下載地址:http://www.lighttpd.net/download/lighttpd-1.4.16.tar.gz

[email protected]:~$ sudo apt-get install lighttpd

[sudo] password for linux:

Reading package lists... Done

Building dependency tree      

Reading state information... Done

The following extra packages will be installed:

  gamin libgamin0 libterm-readkey-perl libterm-readline-perl-perl spawn-fcgi

Suggested packages:

  rrdtool apache2-utils

The following NEW packages will be installed:

  gamin libgamin0 libterm-readkey-perl libterm-readline-perl-perl lighttpd spawn-fcgi

0 upgraded, 6 newly installed, 0 to remove and 623 not upgraded.

Need to get 434 kB of archives.

After this operation, 1,510 kB of additional disk space will be used.

Do you want to continue [Y/n]? y

Get:1 http://cn.archive.ubuntu.com/ubuntu/ precise-updates/universe libgamin0 i386 0.1.10-4ubuntu0.1 [18.6 kB]

Get:2 http://cn.archive.ubuntu.com/ubuntu/ precise-updates/universe gamin i386 0.1.10-4ubuntu0.1 [47.0 kB]

Get:3 http://cn.archive.ubuntu.com/ubuntu/ precise/main libterm-readkey-perl i386 2.30-4build3 [28.4 kB]

Get:4 http://cn.archive.ubuntu.com/ubuntu/ precise/universe libterm-readline-perl-perl all 1.0303-1 [51.9 kB]

Get:5 http://cn.archive.ubuntu.com/ubuntu/ precise/universe lighttpd i386 1.4.28-2ubuntu4 [275 kB]

Get:6 http://cn.archive.ubuntu.com/ubuntu/ precise/universe spawn-fcgi i386 1.6.3-1 [13.4 kB]

Fetched 434 kB in 2s (198 kB/s) 

Selecting previously unselected package libgamin0.

(Reading database ... 148284 files and directories currently installed.)

Unpacking libgamin0 (from .../libgamin0_0.1.10-4ubuntu0.1_i386.deb) ...

Selecting previously unselected package gamin.

Unpacking gamin (from .../gamin_0.1.10-4ubuntu0.1_i386.deb) ...

Selecting previously unselected package libterm-readkey-perl.

Unpacking libterm-readkey-perl (from .../libterm-readkey-perl_2.30-4build3_i386.deb) ...

Selecting previously unselected package libterm-readline-perl-perl.

Unpacking libterm-readline-perl-perl (from .../libterm-readline-perl-perl_1.0303-1_all.deb) ...

Selecting previously unselected package lighttpd.

Unpacking lighttpd (from .../lighttpd_1.4.28-2ubuntu4_i386.deb) ...

Selecting previously unselected package spawn-fcgi.

Unpacking spawn-fcgi (from .../spawn-fcgi_1.6.3-1_i386.deb) ...

Processing triggers for man-db ...

Processing triggers for ufw ...

Processing triggers for ureadahead ...

ureadahead will be reprofiled on next reboot

Setting up libterm-readkey-perl (2.30-4build3) ...

Setting up libterm-readline-perl-perl (1.0303-1) ...

Setting up spawn-fcgi (1.6.3-1) ...

update-alternatives: using /usr/bin/spawn-fcgi.standalone to provide /usr/bin/spawn-fcgi (spawn-fcgi) in auto mode.

update-alternatives: warning: not replacing /usr/share/man/man1/spawn-fcgi.1.gz with a link.

Setting up gamin (0.1.10-4ubuntu0.1) ...

Setting up libgamin0 (0.1.10-4ubuntu0.1) ...

Setting up lighttpd (1.4.28-2ubuntu4) ...

 * Starting web server lighttpd                                                                                  [ OK ]

Processing triggers for libc-bin ...

ldconfig deferred processing now taking place

[email protected]:~$ ps -aux|grep light*

Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html

root       933  0.0  0.3  35732  3728 ?        Ssl  16:54   0:00 lightdm

root       948  1.6  5.2 102672 53364 tty7     Rsl+ 16:54   0:15 /usr/bin/X :0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch -background none

root      1654  0.0  0.3  17852  3776 ?        Sl   16:54   0:00 lightdm --session-child 12 19

www-data  4613  0.0  0.0   5460   880 ?        S    17:10   0:00 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf

linux     4664  0.0  0.0   4372   832 pts/1    S+   17:10   0:00 grep --color=auto light*

[email protected]:~$ lighttpd -V

lighttpd/1.4.28 (ssl) - a light and fast webserver

Build-Date: Dec 20 2011 14:33:34

Event Handlers:

         + select (generic)

         + poll (Unix)

         - rt-signals (Linux 2.4+)

         + epoll (Linux 2.6)

         - /dev/poll (Solaris)

         - kqueue (FreeBSD)

         - libev (generic)

Network handler:

         + sendfile

Features:

         + IPv6 support

         + zlib support

         + bzip2 support

         + crypt support

         + SSL Support

         + PCRE support

         + mySQL support

         + LDAP support

         + memcached support

         + FAM support

         + LUA support

         + xml support

         + SQLite support

         + GDBM support

[email protected]:~$ which lighttpd

/usr/sbin/lighttpd

web伺服器的根目錄是在 /var/www/

[email protected]:~$ cat /etc/lighttpd/lighttpd.conf

server.modules = (

         "mod_access",

         "mod_alias",

         "mod_compress",

        "mod_redirect",

#       "mod_rewrite",

)

server.document-root        = "/var/www"

server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )

server.errorlog             = "/var/log/lighttpd/error.log"

server.pid-file             = "/var/run/lighttpd.pid"

server.username             = "www-data"

server.groupname            = "www-data"

index-file.names            = ( "index.php", "index.html",

                                "index.htm", "default.htm",

                               " index.lighttpd.html" )

url.access-deny             = ( "~", ".inc" )

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

## Use ipv6 if available

#include_shell "/usr/share/lighttpd/use-ipv6.pl"

dir-listing.encoding        = "utf-8"

server.dir-listing          = "enable"

compress.cache-dir          = "/var/cache/lighttpd/compress/"

compress.filetype           = ( "application/x-javascript", "text/css", "text/html", "text/plain" )

include_shell "/usr/share/lighttpd/create-mime.assign.pl"

include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

Lighttpd預設頁面


lighttpd的配置檔案lighttpd.conf

1)使用語句 server.modules = ("mod_cgi")加入 cgi 模組;

2)使用語句 cgi.assign = (".cgi" => "") 設定 cgi模組的副檔名和直譯器。就本語句而言,表示cgi模組的副檔名是“.cgi”且該 cgi模組不需要特別的直譯器來執行

lighttpd configuration

Change the server.modules list inside /etc/lighttpd/lighttpd.conf in:

server.modules              = (
            "mod_access",
"mod_cgi",
            "mod_alias",
            "mod_accesslog",
            "mod_compress",
)

and add these lines:

$HTTP["url"] =~ "/cgi-bin/" {
        cgi.assign = ( "" => "" )
}
cgi.assign      = (
        ".cgi"  => ""
)

Restart lighttpd typing:

debarm:~# /etc/init.d/lighttpd restart

Hello world example

Save this "Hello world !" source code example in/var/www/cgi-bin(create this directory if it not exists).

#include"stdio.h"
int main(void){
  printf("Content-Type: text/plain\n\n");
  printf("Hello world !\n");
return0;
}

Compile it typing:

debarm:~# gcc hello.c -o hello.cgi
[email protected]:/var/www/cgi-bin$ ./hello.cgi 
Content-Type: text/plain
Hello world

Final test

Access with your browser to the FOX Board web page using this URL:

相關推薦

openwrt學習筆記webserverlighttpd

Lighttpd是一個德國人領導的開源軟體,其根本的目的是提供一個專門針對高效能網站,安全、快速、相容性好並且靈活的web server環境。具有非常低的記憶體開銷,cpu佔用率低,效能好,以及豐富的模組等特點。 lighttpd 是眾多OpenSource輕量級的web server中較為優秀的一個。支

Python學習筆記多線程

oop 模擬 筆記 標準庫 函數 只需要 pre 開始 print 摘抄自:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001431928238187

Linux學習筆記awk

awkhead -n2 test.txt|awk -F ‘:‘ ‘{print $1}‘ //文件的前兩行,以:分隔,打印第一段 head -n2 test.txt|awk -F ‘:‘ ‘{print $0}‘ //文件的前兩行,以:分隔,打印所有的內容($N就是第N段,0就是所有字段)

tensorflow學習筆記:collection tensorflow學習筆記:collection

tensorflow學習筆記(二十八):collection 2016年12月27日 11:53:06 閱讀數:11346 tensorflow collection tensorflow的collection提供一個

Effective_STL 學習筆記 瞭解如何通過 reverse_iterator 的 base 得到 iterator

  要實現在一個 reverse_iterator ri 指出的位置上插入新元素,在 ri.base() 指向的位置插入就行了。對於 insert 操作而言,ri 和 ri.base() 是等價的,而且 ri.base() 真的是 ri 真的是 ri 對應的iterator 1   vec

Django學習筆記:伺服器的試用和部署

因為博主穴力,所以一開始的學習都是在虛擬機器上進行的,專案學習的差不多了,是時候學習一下部署了 特意在某雲上買了個伺服器,試試水,看看能不能再15天試用期完成部署的全部操作練習 先在雲主機上設定賬密,這樣方便在xshell上使用 在xshell中新建連線,輸

OpenCV學習筆記——小試SVM演算法ml OpenCV學習筆記——基於級聯分類器的目標檢測objdect OpenCV學習筆記——光流法對運動目標跟蹤Video Ope

OpenCV學習筆記(二十六)——小試SVM演算法ml  總感覺自己停留在碼農的初級階段,要想更上一層,就得靜下心來,好好研究一下演算法的東西。OpenCV作為一個計算機視覺的開源庫,肯定不會只停留在數字影象處理的初級階段,我也得加油,深入研究它的演算法庫。就從ml入手

Unity3D學習筆記:Editor

到你 box -a del eset tools 才會 resources 關於 Editor: 對編輯器進行一些拓展開發 關於繼承Mono類的擴展開發 特性: [特性]:聲明性的標簽(類,方法,結構體,變量) 特性只對字段聲明有效,後面必須接字段;多個特性,可以修

openwrt學習筆記:網路時間同步

在實際的LINUX 開發中,網路裝置都有工作時間,一般需要進行網路時間同步。 一般採用NTP伺服器進行同步。 NTP(Network Time Protocol,網路時間協議)是用來使網路中的各個計算機時間同步的一種協議。它的用途是把計算機的時鐘同步到世界協調時UTC,其精

openwrt學習筆記:WIFI 無線傳輸速率測試-iperf

Iperf是一個TCP/IP和UDP/IP的效能測量工具,能夠提供網路吞吐率資訊,以及震動、丟包率、最大段和最大傳輸單元大小等統計資訊;從而能夠幫助我們測試網路效能,定位網路瓶頸。 現在ubuntu單虛擬機器不同終端以及不同虛擬機器之間的測試為例說明如何安裝以及使用,然後提

Python學習筆記StringIO和BytesIO

nbsp from 寫入 enc print == world! byte 初始化 StringIO 很多時候,數據讀寫不一定是文件,也可以在內存中讀寫。 StringIO顧名思義就是在內存中讀寫str。 要把str寫入StringIO,我們需要先創建一個String

Python學習筆記

準備 for ring 價格 python use imp pri exce 使用ElementTree解析XML文件 # 導入Python中內置的處理XML文件的模塊try: import xml.etree.cElementTree as ETexcept Imp

Java學習筆記:類型轉換和instanceof關鍵字

方法 png true feed out 實例 strong 運算符 nbsp 基本數據類型轉換: 自動類型轉換:把大類型的數據賦值給大類型的變量(此時的大小指的是容量的範圍) 1 byte b = 12; //byte是一個字節 2 int i = b; //i

Linux學習筆記管道符和作業控制、shell變量、環境變量配置文件

環境變量配置文件 管道符 一、管道符和作業控制cat 1.txt |wc -l ; cat 1.txt |grep ‘aaa‘將前面命令的結果輸入給後面的命令ctrl z 暫停一個任務、這時候任務隱藏到後臺,通過fg可以重新吊起任務到前臺運行jobs查看後臺的任務bg[id]把任務調到後臺fg[id]

Linux學習筆記shell特殊符號、 sort_wc_uniq、tee_tr_split

tee_tr_split命令一、特殊字符 1.‘* ‘任意個任意字符‘? ‘任意一個字符‘# ‘註釋字符‘ \ ‘脫義字符‘ | ‘管道符其中大部分之前都用過,對於脫義符‘\‘脫義符用法舉例如圖 2.幾個與管道有關的命令cut 分割,-d 分隔符 -f 指定段號 -c 指定第幾個字符 sort 排序,

Linux學習筆記grep

grepgrepgrep [-cinvABC] ‘word‘ filename -c 行數-i 不區分大小寫-n 顯示行號-v 取反-r 遍歷所有子目錄-A 後面跟數字,過濾出符合要求的行以及下面n行-B 同上,過濾出符合要求的行以及上面n行-C 同上,同時過濾出符合要求的行以及上下各n行 mkdir /tm

Linux學習筆記sed

sedsedsed是一種流編輯器,它是文本處理中非常中的工具,能夠完美的配合正則表達式使用,功能不同凡響。處理時,把當前處理的行存儲在臨時緩沖區中,稱為“模式空間”(pattern space),接著用sed命令處理緩沖區中的內容,處理完成後,把緩沖區的內容送往屏幕。接著處理下一行,這樣不斷重復,直到文件末尾

Linux學習筆記日常運維一

日常運維一、查看系統負載w/uptime 查看系統負載 load average後指系統在一分鐘,五分鐘,十五分鐘內的運行狀態,平均有多少服務在運行負載值大於邏輯cpu數就說明超負荷了,數值小於cpu數是理想狀態 cat /proc/cpuinfo 查看cpu核數processor 後的數字就是cpu數量減一

Linux學習總結 數據同步工具 rsync

rsyncrsync是linux系統下的數據鏡像備份工具。使用快速增量備份工具Remote Sync可以遠程同步,支持本地復制,或者與其他SSH、rsync主機同步。 rsync格式 rsync [OPTION] … SRC DEST rsync [OPTION] … SRC [user@]host:

nginx 原始碼學習筆記—— event 模組() ——事件驅動核心ngx_process_events_and_timers

首先繼續回憶下,之前子執行緒執行操作裡面有一個未涉及的內容ngx_process_events_and_timers,今天我們就來研究下這個函式。 本篇文章來自於:http://blog.csdn.net/lengzijian/article/details/7601730 先來看一下第十九