CentOS搭建配置lighttpd(php、Virtual Host)

89401052 2010-09-29

一、解压lighttpd-1.4.23.tar.gz
[root@localhost ~]# tar zxvf lighttpd-1.4.23.tar.gz

二、试安装lighttpd-1.4.23
[root@localhost ~]# cd lighttpd-1.4.23
[root@localhost lighttpd-1.4.23]# ./configure --prefix=/usr/local/lighttpd
configure: error: in `/root/lighttpd-1.4.23':
configure: error: no acceptable C compiler found in $PATH

三、配置yum网站
1、安装gcc出现错误
[root@localhost yum.repos.d]# yum install gcc
Could not retrieve mirrorlist http://mirrorlist.CentOS.org/?release=5&arch=x86_64&repo=addons error was
[Errno 4] IOError: <urlopen error (-3, 'Temporary failure in name resolution')>
Error: Cannot find a valid baseurl for repo: addons
2、修改yum目录及设置域名服务
[root@localhost lighttpd-1.4.23]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vi CentOS-Base.repo
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
改为
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
另:国内镜像http://centos.ustc.edu.cn
[root@localhost yum.repos.d]# echo "nameserver 8.8.8.8" >> /etc/resolv.conf
Google承诺将严格遵循DNS协议,即不阻挡、不劫持和不过滤用户查询。
Google Public DNS服务器IP
8.8.8.8        google-public-dns-a.google.com
8.8.4.4        google-public-dns-b.google.com
3、确认能访问mirrorlist.centos.org
[root@localhost yum.repos.d]# ping mirrorlist.centos.org

四、安装gcc
[root@localhost yum.repos.d]# yum install gcc

五、安装其他包
[root@localhost yum.repos.d]# yum install pcre pcre-devel zlib-devel bzip2 bzip2-devel

六、安装lighttpd-1.4.23
[root@localhost yum.repos.d]# cd ~/lighttpd-1.4.23
[root@localhost lighttpd-1.4.23]# ./configure --prefix=/usr/local/lighttpd
[root@localhost lighttpd-1.4.23]# make
[root@localhost lighttpd-1.4.23]# make install

七、配置lighttpd-1.4.23
[root@localhost lighttpd-1.4.23]# cp ./doc/lighttpd.conf /usr/local/lighttpd/
[root@localhost lighttpd-1.4.23]# cd /usr/local/lighttpd/
[root@localhost lighttpd]# vi lighttpd.conf
server.modules              = (
                                "mod_rewrite",
                                "mod_redirect",
                                "mod_alias",
                                "mod_access",
#                               "mod_trigger_b4_dl",
#                               "mod_auth",
#                               "mod_status",
#                               "mod_setenv",
#                               "mod_fastcgi",
                                "mod_proxy",
#                               "mod_simple_vhost",
                                "mod_evhost",  #虚拟主机
#                               "mod_userdir",
#                               "mod_cgi",
#                               "mod_compress",
#                               "mod_ssi",
#                               "mod_usertrack",
#                               "mod_expire",
#                               "mod_secdownload",
#                               "mod_rrdtool",
                                "mod_accesslog" )

 

server.document-root        = "/var/www/htdocs/"

#proxy
#tomcat proxy 域名转向TOMCAT
$HTTP["host"] == "www.6688.cc" {
  proxy.server  = ( "" => ( (  "host" => "192.168.0.243",
                                "port" => 8001,
                                "fix-redirects" => 1
) ) )
}

 

#Virtual Host
$HTTP["host"] == "www.linuxidc.net" {
  server.name = "www.linuxidc.net"
  server.document-root = "/var/www/htdocs/test"
  server.errorlog = "/var/log/lighttpd/test-error.log"
  accesslog.filename = "/var/log/lighttpd/test-access.log"
}


八、建立相关目录
[root@localhost lighttpd]# mkdir -p /var/log/lighttpd
[root@localhost lighttpd]# mkdir -p /var/www/htdocs
[root@localhost lighttpd]# cd /var/www/htdocs
[root@localhost htdocs]# vi index.html
<html><body><h1>It works on lighttpd</h1></body></html>
启动lighttpd
[root@localhost htdocs]# /usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/lighttpd.conf
搭建http端口为8001的TOMCAT
WINDOWS平台可在C:\WINDOWS\system32\drivers\etc\hosts文件加上192.168.0.243 www.6688.cc
即可通过www.6688.cc访问lighttpd域名转向


九、配置light支持php
1、安装php
[root@localhost ~]# yum install php
[root@localhost ~]# /usr/bin/php-cgi -v
出现的信息中有个(cgi-fcgi)表示支持fast-cgi了
2、配置ighttpd.conf
[root@localhost ~]# cd /usr/local/lighttpd/
[root@localhost lighttpd]# vi ighttpd.conf
将 #     "mod_fastcgi" 的#去掉
#### 配置fastcgi的定义
#### fastcgi module
## read fastcgi.txt for more info
## for PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/bin/php-cgi"
)
)
)
3、创建相关资源
[root@localhost lighttpd]# mkdir -p /var/run/lighttpd/
[root@localhost lighttpd]# cd /var/run/lighttpd/
[root@localhost lighttpd]# touch php-fastcgi.socket-0
[root@localhost lighttpd]# touch php-fastcgi.socket-0
重启lighttpd即可。

相关推荐