ubuntu配置lighttpd服务器

版本:

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

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值