1、有兩種管道下載下傳源碼,分别是: http://www.lighttpd.net/download/ -- 官網 https://github.com/lighttpd
-- GitHub
官網下載下傳的源碼和GitHub的略有不同,我們以前者,也就是官網的為準。
2、我們下載下傳版本lighttpd-1.4.20.tar.gz,解壓之後發現它是make版本,沒有cmake檔案。我們從GitHub v1.4.21版本拉取,github上面的源碼是帶有cmakelists檔案的(從v1.4.21版本開始)。整合之後,就可以實作lighttpd-1.4.20的cmake編譯。
記得修改一處:/src/CMakeLists.txt,第471行,因為官網1.4.20的源碼沒有mod_uploadprogress.c檔案
#ADD_AND_INSTALL_LIBRARY(mod_uploadprogress mod_uploadprogress.c)
完整的cmake工程源碼請見:
https://download.csdn.net/download/libaineu2004/108432673、使用IDE Qt Creator來編譯源碼。編譯完成會在路徑生成可執行檔案:
build-lighttpd-1.4.20-cmake-Desktop_Qt_5_9_7_GCC_64bit-Debug/build/lighttpd
及一系列的*.so的插件庫檔案。
終端指令行,啟動lighttpd的方法是:
[root@localhost build]# ./lighttpd -D -f lighttpd.conf -m .
其中-D表示調試模式,非守護程序運作;
-f lighttpd.conf表示指定的配置檔案;
-m .表示指定的*.so庫檔案路徑,這裡的"."表示so檔案都在目前路徑。
注意,每次運作必須指明庫檔案*.so的路徑,否則會報錯:
mod_indexfile.so: cannot open shared object file: No such file or directory
4、lighttpd.conf幾個重要的配置項
#代表網站存放的路徑
server.document-root = "/home/firecat/"
## where to send error-messages to 錯誤日志的路徑
server.errorlog = "/var/log/lighttpd/error.log"
#firecat建議注釋掉chroot/username/groupname這三項
### only root can use these options
#
# chroot() to directory (default: no chroot() )
#server.chroot = "/"
## change uid to <uid> (default: don't care)
#server.username = "www-data"
## change uid to <uid> (default: don't care)
#server.groupname = "www-data"
#守護程序的檔案名
server.pid-file = "/var/run/lighttpd.pid"
# files to check for if .../ is requested
server.indexfiles = ( "index.php", "index.html",
"index.htm", "default.htm" )
5、運作測試
編寫一個簡單的網頁,另存為index.html檔案,utf-8格式
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>lighttpd測試</title>
</head>
<body>
<p>輕量級web伺服器lighttpd的編譯及配置(for x86-linux)</p>
<hr>
<p>測試頁面</p>
</body>
</html>
然後拷貝到Linux路徑/home/firecat/
啟動Lighttpd伺服器,在浏覽器輸入
http://127.0.0.1/,即可輸出: