关于web之前真没有接触过,上个星期经理给了任务,让我搭建一个Lighttpd的环境,本来以为很简单,结果没想到让我弄了很久,具体多久不说了丢人,下面就写我在搭建的时候遇到的各种各样的问题,还有看到其他博主遇到的一些问题,都写在这把
第一步:首先是下载https://www.lighttpd.net/ 网址就不多说了,具体问题就是版本号的问题,我这里是用版本:lighttpd-1.4.41.tar.gz
第二步:解压包 tra -zxvf lighttpd-1.4.41.tar.gz
第三步:./configure --prefix=/usr/local/lighttpd 执行这一步基本上就有一些问题出来了 我就列举在下面了
出现configure: error: C compiler cannot create executables … 安装sudo apt-get install libc6-dev.
出现configure: error: configure: error: pcre-config not found … 安装sudo apt-get install libpcre3-dev
出现configure: error: zlib-headers and/or libs where not found … 安装sudo apt-get install zlib1g-dev
出现configure: error: bzip2-headers and/or libs where not found … 安装sudo apt-get install libbz2-dev
第三步: make && sudo make install执行好上一步,这俩步就没问题,
第四步:然后就是配置文件的问题了(这一步我就直接从别的网址摘下来了,不在手打了)
cp -p doc/config/lighttpd.conf /etc/lighttpd/lighttpd.conf #复制配置文件到配置目录下
cp -p doc/initscripts/sysconfig.lighttpd /etc/sysconfig/lighttpd
mkdir /etc/lighttpd ##创建配置文件目录
cp -R doc/config/conf.d/ doc/config/*.conf doc/config/vhosts.d/ /etc/lighttpd/ #复制配置文件
配置lighttpd.conf文件
vim /etc/lighttpd/lighttpd.conf
################################################
var.log_root = "/www/logs" ##错误日志根目录
var.server_root = "/www" ##网站根目录(记得自己创建,一会测试用的到)
var.state_dir = "/var/run" ##lighttpd运行目录
var.home_dir = "/www"
var.conf_dir = "/etc/lighttpd" ##配置目录
注意自己的网站目录地址
var.vhosts_dir = server_root + "/vhosts"
var.cache_dir = "/www" ##缓存目录
var.socket_dir = home_dir + "/sockets"
include "modules.conf"
server.port = 80 # 服务监听端口 (不要设置80,记得要改成别的,80防火墙会给你屏蔽)
server.username = "nobody" ##lighttpd的用户(用什么权限来运行lighttpd)
server.groupname = "nobody" ##lighttpd的用户组
server.document-root = server_root + "/htdocs" ##网站存放站点
server.pid-file = state_dir + "/lighttpd.pid" 进程id记录位置
server.errorlog = log_root + "/error.log" # 错误日志位置
include "conf.d/access_log.conf"
include "conf.d/debug.conf"
server.event-handler = "linux-sysepoll"
server.network-backend = "sendfile"
server.max-fds = 2048 ##最大连接数,大流量网站推荐2048
server.stat-cache-engine = "simple"
server.max-connections = 1024
index-file.names += (
"index.xhtml", "index.html", "index.htm", "default.htm", "index.php"
)
url.access-deny = ( "~", ".inc" )
$HTTP["url"] =~ "\.pdf$" {
server.range-requests = "disable"
}
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".scgi" )
include "conf.d/mime.conf"
include "conf.d/dirlisting.conf"
server.follow-symlink = "enable"
server.upload-dirs = ( "/var/tmp" )
include_shell "cat /etc/lighttpd/vhosts.d/*.conf"
###################################################################################
以上是lighttpd.conf 的文件内容(对了这里我把server.bind = "192.168.xxx.xxx"打开了记得设置ip,)
modules.conf 配置文件内容 讲下面行前面的注释#去掉
#################################################################################
server.modules = (
"mod_access",
"mod_rewrite",
include "conf.d/compress.conf"
include "conf.d/fastcgi.conf"
include "conf.d/cgi.conf"
include "conf.d/simple_vhost.conf"
###############################################################################
开设多部虚拟机
##############################################################################
lighttpd虚拟主机配置
$HTTP["host"] == "bbs.xxx.com" {
server.name = "bbs.xxx.com" ##可不用
server.document-root = "/www/vhosts/bbs.xxx.com"
server.errorlog = "/www/vhosts/bbs.xxx.com/error.log"
accesslog.filename = "/www/vhosts/bbs.xxx.com/access.log"
}
##############################################################################
# 针对端口的虚拟主机
$SERVER["socket"] == "192.168.0.1:8000" {
server.document-root = "/var/www/xxx/"
server.errorlog = "/var/log/lighttpd/test-error.log"
accesslog.filename = "/var/log/lighttpd/test-access.log"
}
#############################################################################
配置/etc/lighttpd/conf.d/fastcgi.conf 文件调用php文件
server.modules += ( "mod_fastcgi" )
fastcgi.server = (
".php" => ((
"host" => "127.0.0.1",
"port" => "9000",
#"docroot" => "/www/htdocs"
)))
(记得自己创建html的文件,一会我们好测试 用,我是在/home/用户名/下创建了一个web的文件夹,里面 放了测试文件)
第五步:运行测试,现在我cd到 lighttpd-1.4.41 进入 src 然后 ./lighttpd -d -f /etc/lighttpd/lighttpd.conf
出了OK 就没问题了.然后开始测 sudo ./lighttpd -f /etc/lighttpd/lighttpd.conf 完成之后服务器也起来基本大功告成通过浏览器就可以访问了!!!但是,我就是被坑死的当我打开 192.168.161.133:8888 (我之前设好的IP跟端口) 弹出来403的错误
HTTP 错误 403.14 - Forbidden
就是这货,我以为是我之前没有配置好文件,其实就是你那个测试文件没权限 chmod 给那个文件 满权限就好了 ,这就可以了
问题应该就这么多了吧,我也很菜B,也是没毕业多久,开个博客,就从现在开始记录我工作中遇到的各种问题吧