版本:
ubuntu:18.04
lighttpd:1.4.45
apt-get update
apt-get install lighttpd
启动:service lighttpd start
停止:service lighttpd stop
重启:service lighttpd restart
启动后访问ip,如果是在本地服务器上跑的,则可以直接访问127.0.0.1。
如果能显示下面这个页面,则表示服务器成功运行。
路径:/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"
将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
首先配置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为:
修改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