版本:
ubuntu:18.04
lighttpd:1.4.45
1、下載安裝
apt-get update
apt-get install lighttpd
2、啓動停止
啓動:service lighttpd start
停止:service lighttpd stop
重啓:service lighttpd restart
啓動後訪問ip,如果是在本地服務器上跑的,則可以直接訪問127.0.0.1。
如果能顯示下面這個頁面,則表示服務器成功運行。
3、lighttpd的配置文件的一些介紹
路徑:/etc/lighttpd/lighttpd.conf
# 配置server.modules字段決定Lighttpd使用哪些擴展模塊
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
)
server.document-root = "/var/www/html" # html文件根路徑
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" # Lighttpd進程的歸屬用戶
server.groupname = "www-data" # Lighttpd 進程的歸屬羣組
server.port = 80 # 服務器端口號
# 如果網站目錄中出現以下文件名,不用指定文件名便可直接訪問
index-file.names = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny = ( "~", ".inc" ) # 禁止訪問文件類型
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" )
# default listening port for IPv6 falls back to the IPv4 port
## Use ipv6 if available
#include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
4、html存放路徑以及訪問頁面的url
將html文件放入上面配置文件lighttpd.conf設置的html根目錄:/var/www/html中,例:將hello.html放入,則url爲:127.0.0.1:80/hello.html
也可以在html中新建文件夾,比如創建一個abc文件夾,再將hello.html放入abc文件夾中,則此時訪問hello.html的url爲:127.0.0.1:80/abc/hello.html
5、啓用cgi(如不開啓cgi功能,在訪問cgi文件時就不會調用cgi程序,而是把cgi文件下載下來了)
首先配置cgi路徑,在/etc/lighttpd/lighttpd.conf末尾加入如下語句:
alias.url = ( "/cgi-bin/" => "/var/www/cgi-bin/" )
然後使用命令開啓cgi功能,直接在shell中輸入以下命令:
lighty-enable-mod cgi
service lighttpd force-reload
將cgi文件放入路徑:/var/www/cgi-bin中,這時要調用cgi程序,例如form表單提交到一個指定cgi處理的url爲:
<form action="/cgi-bin/xxx.cgi" method="POST" name="form1">
6、啓用SSI
修改lighttpd.conf配置
在server.modules中添加 mod_ssi 項,注意如果配置了 mod_compress 項,則mod_ssi項要寫在 mod_compress 項前。
server.modules = (
"mod_access",
"mod_alias",
"mod_ssi",
"mod_compress",
"mod_redirect",
)
另外在配置最後添加:
ssi.extension = ( ".shtml" )
並將使用ssi的html文件的後綴改爲.shtml。
還有一些其他配置暫時沒用到,沒做嘗試,如果需要可以參考以下文章
參考:
https://raspberrypi.stackexchange.com/questions/74579/running-cgi-scripts-with-lighttpd
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ConfigurationOptions
https://blog.csdn.net/u014745198/article/details/53671817
https://www.cnblogs.com/zhoujinyi/archive/2012/11/14/2769424.html