LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2156|回复: 4

lighttpd虚拟主机的问题---(已解决)

[复制链接]
发表于 2007-3-24 01:07:31 | 显示全部楼层 |阅读模式
lighttpd的虚拟主机不会弄。
如果将 $HTTP["host"] == "www.mydomain.com" { 这行注释掉(还有“}”),就能正常运行,否则服务器起不来。

lighttpd.conf如下:

##############
# variables
var.logdir   = "/var/log/lighttpd"
var.statedir = "/var/lib/lighttpd"

##############
# modules
# NOTE: the order of modules is important.
server.modules = (
    "mod_rewrite",
    "mod_alias",
    "mod_access",
    "mod_fastcgi",
    "mod_evhost",   
    "mod_compress",
    "mod_accesslog"
)

##############
# server settings
server.username      = "lighttpd"
server.groupname     = "lighttpd"
server.pid-file      = "/var/run/lighttpd.pid"
server.indexfiles    = ( "index.html", "index.php", "index.rhtml" )
server.follow-symlink = "enable"
server.event-handler = "linux-sysepoll"

##############
# mod_staticfile
static-file.exclude-extensions = (".php", ".rhtml", ".pl", ".cgi", ".fcgi")

##############
# mod_access
url.access-deny = ("~", ".inc", ".pl", ".sh")

##############
# mod_compress
compress.cache-dir   = var.statedir + "/cache/compress"
compress.filetype    = ("text/plain", "text/html")


##############
# virtual hosts
$HTTP["host"] == "www.mydomain.com" {
    server.name = "www.mydomain.com"
    server.document-root = "/var/www/mydomain"
    server.error-handler-404 = "/var/www/mydomain/404.html"
    server.errorlog = var.logdir  + "/mydomain_error.log"
    accesslog.filename   = var.logdir + "/mydomain_access.log"
    fastcgi.server = ( ".php" =>
                            ( "www.mydomain.com" =>
                                    (
                                            "host"                =>    "127.0.0.1",
                                            "port"                =>        1026,
                                            "bin-path"        =>        "/usr/bin/php-cgi"
                                    )
                               )
                         )           
}


##############
# mime types
include "mimetype.conf"
发表于 2007-3-24 10:18:13 | 显示全部楼层
匹配地址不应该用“==”的吧,应该用“=~“,也就是正则表达式的匹配符号。
另外,我记得严格来讲,地址中的"."符号要转义成"\."才行。
你写成这样试试看:
$HTTP["host"] =~ "www\.mydomain\.com" {
……………………
}
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-3-24 10:34:16 | 显示全部楼层
如果不需要模糊匹配的话,不需要使用正则表达式,"==" 可以的。
现在的问题是注释掉的话,就好的,否则服务器起不来。没有语法报错,error.log里也没有原因。

下面这样就好了:
#$HTTP["host"] == "www.mydomain.com" {
……………………
#}
回复 支持 反对

使用道具 举报

发表于 2007-3-24 12:45:09 | 显示全部楼层
服务器起不来?启动不了还是网站访问不了呢?
既然注释掉了就好了,那么这句有问题的可能性就很大啊
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-3-24 13:03:24 | 显示全部楼层
问题解决了!就是不知道这样解决是不是对的,呵呵。原来server.document-root必须有一个默认的。

报错如下:
#/usr/sbin/lighttpd -f mylighttpd.conf
2007-03-24 12:37:17: (configfile.c.1095) a default document-root has to be set
2007-03-24 12:37:17: (server.c.563) setting default values failed

看configfile.c的源码
1060         int config_set_defaults(server *srv) {
1061                 size_t i;
1062                 specific_config *s = srv->config_storage[0];
.............
1094                 if (buffer_is_empty(s->document_root)) {
1095                         log_error_write(srv, __FILE__, __LINE__, "s",
1096                                         "a default document-root has to be set");
1097        
1098                         return -1;
1099                 }

我的配置里明明有
#$HTTP["host"] == "www.mydomain.com" {
……………………
server.document-root = "/var/www/mydomain"
……………………
#}
估计是在匹配$HTTP["host"]之前,判断了server.document-root为空(没有再去研究源码 了,人懒,呵呵)。于是在配置文件前面加了个默认的,服务器启动成功。

另外lighttpd的-p参数可以看到程序最终运行的配置文件,这个蛮管用的。
#/usr/sbin/lighttpd -f mylighttpd.conf -p | less
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表