lighttpd + FastCGI + Mono 在启用 evhost 的情况下无法运行

lighttpd + FastCGI + Mono 在启用 evhost 的情况下无法运行

我已经开始将 Windows VPS 迁移到 linode.com,选择 lighttpd 而不是 nginx 和 apache 来托管一些基于 asp.net mvc 构建的站点,但我遇到了我认为是“文档根”冲突的问题。

我在 Ubuntu 10.04 上运行 lighttpd 1.4.6、Mono 2.8.2

我已使用以下模式配置了 mod_evhost 以匹配此目录结构:

/var/webs/country-tld.tld.domain/www
/var/webs/country-tld.tld.domain/subdomain

并从请求中删除所有“www”,重定向到 url,并且对于静态内容一切都正常工作,但是在加载 aspx 页面时,我不断收到 default.aspx 的 404 错误。

当我将 server.document-root 设置为任何网站(绕过 evhost 规则)时,Mono 工作正常,按预期提供 aspx 页面。这让我想到,当启用 evhost 时,“MONO_FCGI_ROOT”= server.document-root 会与其余配置混合,导致 aspx 内容出现 404。

有人有设置此环境的经验吗?在使用 Apache+mod_mono 设置所有内容之前,我真的想给 lighttpd 的配置优雅和简单一个机会,或者为每个主机使用单独的 fastcgi 映射。

这些是我的配置文件。

/etc/lighttpd/lighttpd.conf:

server.modules = (
    "mod_access",
    "mod_alias",
    "mod_accesslog",
    "mod_compress",
    "mod_rewrite",
    "mod_redirect",
    "mod_evhost"
)

server.document-root = "/var/webs/default/"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"

index-file.names = (
    "index.html",
    "index.htm",
    "default.htm",
    "default.html"
)

accesslog.filename = "/var/log/lighttpd/access.log"

url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

server.port = 80
server.pid-file = "/var/run/lighttpd.pid"
server.dir-listing = "enable"
server.username = "www-data"
server.groupname = "www-data"
#server.error-handler-404  = "/error-handler.html"

dir-listing.encoding = "utf-8"

compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = (
    "text/plain", 
    "text/html", 
    "application/x-javascript", 
    "text/css"
)
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

### for global domains with 3 or more letters in last .ext
### and for national domains but -no- second level
$HTTP["host"] =~ "^(www.)?([^.]+)\.([a-z]{2,})$" {
  evhost.path-pattern = "/var/webs/%1.%2/www/"
}
$HTTP["host"] =~ "^(www.)?([^.]+)\.([^.]+)\.([a-z]{2,})$" {
  evhost.path-pattern = "/var/webs/%1.%2/%3/"
}
### for second level national domains with 2 letters in last .ext
###  %4       %3      %2    %1
### sub   domain  subtld   tld
$HTTP["host"] =~ "^(www.)?([^.]+)\.([a-z]{2,3})\.([a-z]{2})$" {
  evhost.path-pattern = "/var/webs/%1.%2.%3/www/"
}
$HTTP["host"] =~ "^(www.)?([^.]+)\.([^.]+)\.([a-z]{2,3})\.([a-z]{2})$" {
  evhost.path-pattern = "/var/webs/%1.%2.%3/%4/"
}

# redirect "www.domain" to "domain" preserving the parameters
$HTTP["host"] =~ "^www\.(.*)$" {
  url.redirect = ( "^/(.*)" => "http://%1/$1" )
}


#### handle Debian Policy Manual, Section 11.5. urls
## by default allow them only from localhost
## (This must come last due to #445459)
## Note: =~ "127.0.0.1" works with ipv6 enabled, whereas == "127.0.0.1" doesn't
$HTTP["remoteip"] =~ "127.0.0.1" {
    alias.url += (
        "/doc/" => "/usr/share/doc/",
        "/images/" => "/usr/share/images/"
    )
    $HTTP["url"] =~ "^/doc/|^/images/" {
        dir-listing.activate = "enable"
    }
}

/etc/lighttpd/conf-enabled/10-fastcgi.conf:

index-file.names += (
    "index.aspx",
    "default.aspx",
    "Index.aspx",
    "Default.aspx"
)

var.mono_dir = "/opt/mono-2.8.2/"
var.mono_shared_dir = "/tmp/"
var.mono_fastcgi_server = mono_dir + "bin/" + "fastcgi-mono-server2"
var.mono_fcgi_root = server.document-root
var.mono_fcgi_applications = "/:."

server.modules   += ( "mod_fastcgi" )

fastcgi.server = (
        ".aspx" => ((
                "socket" => mono_shared_dir + "fastcgi-mono-server",
                "bin-path" => mono_fastcgi_server,
                "bin-environment" => (
                        "PATH" => "/bin:/usr/bin:" + mono_dir + "bin",
                        "LD_LIBRARY_PATH" => mono_dir + "lib:",
                        "MONO_SHARED_DIR" => mono_shared_dir,
                        "MONO_FCGI_LOGLEVELS" => "Standard",
                        "MONO_FCGI_LOGFILE" => mono_shared_dir + "fastcgi.log",
                        "MONO_FCGI_ROOT" => mono_fcgi_root,
                        "MONO_FCGI_APPLICATIONS" => mono_fcgi_applications
                ),
                "max-procs" => 1,
                "check-local" => "disable"
        ))
)

fastcgi.map-extensions = (
        ".asmx"   => ".aspx",
        ".ashx"   => ".aspx",
        ".asax"   => ".aspx",
        ".ascx"   => ".aspx",
        ".soap"   => ".aspx",
        ".rem"    => ".aspx",
        ".axd"    => ".aspx",
        ".cs"     => ".aspx",
        ".config" => ".aspx",
        ".dll"    => ".aspx"
)

相关内容