lighttpd伪静态的配置

[不指定 2010/06/08 07:59 | by admin ]
伪静态:

一、以下为discuz7.2的伪静态为例
在lighttpd.conf里,查找#### CGI module
在下面加上:

#  $HTTP["host"] =~ "^192.168.0.2$" {
url.rewrite-once = (
"^(.*)/archiver/((fid|tid)-[w-]+.html)$" => "$1/archiver/index.php?$2",
"^(.*)/forum-([0-9]+)-([0-9]+).html$" => "$1/forumdisplay.php?fid=$2&page=$3",
"^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$" => "$1/viewthread.php?tid=$2&extra=page%3D$4&page=$3",
"^(.*)/space-(username|uid)-(.+).html$" => "$1/space.php?$2=$3",
"^(.*)/tag-(.+).html$" => "$1/tag.php?name=$2"
)
#}

重启lighttpd

二、以下为DZX伪静态,不支持子目录

url.rewrite-once = (

"^(.*)/topic-(.+)\.html$" =>

"/portal.php?mod=topic&topic=$2",

"^(.*)/article-([0-9]+)\.html$" =>

"/portal.php?mod=view&aid=$2",

"^(.*)/forum-(\w+)-([0-9]+)\.html$" =>

"/forum.php?mod=forumdisplay&fid=$2&page=$3",

"^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$"  => "/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3",

"^(.*)/group-([0-9]+)-([0-9]+)\.html$" =>

"/forum.php?mod=group&fid=$2&page=$3",

"^(.*)/space-(username|uid)-(.+)\.html$" =>

"/home.php?mod=space&$2=$3",

"^(.*)/([a-z]+)-(.+)\.html$" =>

"/$2.php?rewrite=$3"

)

三、以下为dzx通用目录规则,同时适用于主目录和子目录

url.rewrite-once = (

"^(.*)/topic-(.+)\.html$" =>

"$1/portal.php?mod=topic&topic=$2",

"^(.*)/article-([0-9]+)\.html$" =>

"$1/portal.php?mod=view&aid=$2",

"^(.*)/forum-(\w+)-([0-9]+)\.html$" =>

"$1/forum.php?mod=forumdisplay&fid=$2&page=$3",

"^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$"  =>
"$1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3",

"^(.*)/group-([0-9]+)-([0-9]+)\.html$" =>

"$1/forum.php?mod=group&fid=$2&page=$3",

"^(.*)/space-(username|uid)-(.+)\.html$" =>

"$1/home.php?mod=space&$2=$3",

"^(.*)/([a-z]+)-(.+)\.html$" =>

"$1/$2.php?rewrite=$3"

)

lighttpd虚拟主机的配置

[不指定 2010/06/08 07:58 | by admin ]
一、常规虚拟主机的配置

1、在lighttpd.conf最后加上如下代码:

$HTTP["host"] == "www.a.com" {
server.name = "www.a.com"
server.document-root = "/home/wwwroot/htdocs/a"
server.errorlog = "/var/log/lighttpd/www.a.com-error.log"
accesslog.filename = "/var/log/lighttpd/www.a.com-access.log"
}


$HTTP["host"] == "www.b.com" {
server.name = "www.b.com"
server.document-root = "/home/wwwroot/htdocs/b"
server.errorlog = "/var/log/lighttpd/www.b.com-error.log"
accesslog.filename = "/var/log/lighttpd/www.b.com-access.log"
}

2、另建lighttpd-vhost.conf,并在lighttpd.conf里调用
在lighttpd.conf最后加上:
include "/etc/lighttpd/lighttpd-vhost.conf"
新建的lighttpd-vhost.conf内容为:

$HTTP["host"] == "www.a.com" {
server.name = "www.a.com"
server.document-root = "/home/wwwroot/htdocs/a"
server.errorlog = "/var/log/lighttpd/www.a.com-error.log"
accesslog.filename = "/var/log/lighttpd/www.a.com-access.log"
}


$HTTP["host"] == "www.b.com" {
server.name = "www.b.com"
server.document-root = "/home/wwwroot/htdocs/b"
server.errorlog = "/var/log/lighttpd/www.b.com-error.log"
accesslog.filename = "/var/log/lighttpd/www.b.com-access.log"
}

我喜欢用这种方法,文件较简洁,虚拟主机配置全部放入单独的lighttpd-vhost.conf文件,这种方法是参考apache虚拟主机而改来的,在nginx下同样适用。

二、简单虚拟主机

简单的虚拟主机需要使用mod_simple_vhost模块.它的特点是简单的就可以绑定域名,但是如果在商业运作当中,这样也是有很大隐患!在这里只需要将这个模块添加到server.modules中,即:

server.modules              = (
...
"mod_simple_vhost",
...
)

一个完整的document root由三个值server-root、hostname、document-root决定
我们可以这样设定:

simple-vhost.server-root         = "/var/www"
simple-vhost.document-root       = "/public_html/"

Sponsored Links
如果按照以上这样设定,那么我们便可以很方便的绑定多个域名到服务器,只需要在/var/www目录添加文件夹,文件夹就输入需要绑定的域名,然后进入文件夹,在里面建立public_html文件夹就可以实现绑定了.那么完整的路径便是

/var/www/www.xmlchina.org/public_html


三、复杂虚拟设置匹配

复杂虚拟设置匹配,在这里同样需要开启模块的支持,即在server.modules中添加mod_evhost即可,方法如上.

复杂虚拟设置匹配,一般可以用作泛域名解析用,它是使用正则进行匹配,如此便可以实现多子域名的绑定.

在lighttpd.conf中便有这一条的解释

# define a pattern for the host url finding
# %% => % sign
# %0 => domain name + tld
# %1 => tld
# %2 => domain name without tld
# %3 => subdomain 1 name
# %4 => subdomain 2 name
#
# evhost.path-pattern = "/home/storage/dev/www/%3/htdocs/"

那么我们可以按照官方的方法进行设置,下面是我的配置.

$HTTP["host"] =~ "www.xmlchina.org$" {
evhost.path-pattern        = "/var/www/%0/%3"
}

%0 = xmlchina.org
%3 = www
这里文档路径是/var/www/xmlchina.org/www

还可进行二级域名解析,如:

$HTTP["host"] =~ "^(.*).xmlchina.org$" {
evhost.path-pattern        = "/var/www/%0/%3"
}

%0 = xmlchina.org
%3 = 任意第二级域名前缀

复杂虚拟设置匹配可以实现可变目录的绑定,轻松解决多二级域名的解析难题

总结

这里提供的三个方法,各有各的好处.但是就服务器安全角度来说,建议使用第一条.原因嘛!慢慢琢磨啦.

phpfastcgi+lighttpd的安装

[不指定 2010/06/08 07:28 | by admin ]
lighttpd的安装
1、先安装mysql
2、安装php,php的编译参数加上 --enable-fastcgi --enable-force-cgi-redirect
3、安装lighttpd
   a、安装pcre
        tar zxvf pcre-7.9.tar.gz
        cd pcre-7.9/
        ./configure
        make
        make install
        cd ../
    b、安装lighttpd
        tar xzvf lighttpd-1.4.26.tar.gz
        cd lighttpd-1.4.26
        ./configure --prefix=/web/lighttpd
        make
        make install

mkdir /etc/lighttpd
cp doc/lighttpd.conf /etc/lighttpd/
cp doc/sysconfig.lighttpd /etc/sysconfig/lighttpd
cp doc/rc.lighttpd.redhat /etc/init.d/lighttpd

vi /etc/init.d/lighttpd
lighttpd="/usr/sbin/lighttpd修改为lighttpd="/web/lighttpd/sbin/lighttpd" 改为你的lighttpd的安装路径
vi /etc/lighttpd/lighttpd.conf  修改配置文件

打开需要的模块,去掉前面的# ( "mod_rewrite",  "mod_alias", "mod_access", "mod_fastcgi",  "mod_cgi",   "mod_compress", "mod_accesslog" )

server.document-root        = "/srv/www/htdocs/"   修改为自己的路径
如:
server.document-root        = /home/wwwroot/htdocs

#server.pid-file            = "/var/run/lighttpd.pid"   打开这一句
#server.username            = "wwwrun"   改成自己的用户
#server.groupname           = "wwwrun"    改成自己的用户组
如自己加一个
groupadd wwwrun
useradd wwwrun -g wwwrun -d /home/wwwroot/htdocs -s /sbin/nologin

查找下面的:
#fastcgi.server             = ( ".php" =>
#                               ( "localhost" =>
#                                 (
#                                   "socket" => "/var/run/lighttpd/php-f        astcgi.socket",
#                                   "bin-path" => "/usr/local/bin/php-cg        i"
#                                 )
#                               )
#                            )
打开
#cgi.assign                 = ( ".pl"  => "/usr/bin/perl",
#                               ".cgi" => "/usr/bin/perl" )
打开

mkdir -p /var/run/lighttpd/
chown -R www.www /var/run/lighttpd/
chmod -R 777 /var/run/lighttpd/
mkdir -p /var/log/lighttpd/
chmod -R 777 /var/log/lighttpd/
上面一段较重要,否则会启动不了lighttpd

chkconfig --add lighttpd
chkconfig lighttpd on
service lighttpd start

在/home/wwwroot/htdocs里建个phpinfo.php进行测试
phpinfo();
?>
分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]