Ruby on rails Lighttpd/FastCGI将路由视为静态内容

Ruby on rails Lighttpd/FastCGI将路由视为静态内容,ruby-on-rails,fastcgi,lighttpd,Ruby On Rails,Fastcgi,Lighttpd,我在FastCGI和Rails中遇到了一个令人沮丧的问题,lighttpd将路由url视为静态文件,即不将它们发送到Rails,因为它认为它们是静态的 如果我点击根路径,我会得到rails应用程序,但只要我点击了带有URL结构的内容,甚至是匹配默认:controller/:action路由的路径,我就会从lighttpd得到404,而rails应用程序甚至都不会被查询 这是我的lighttpd.conf: server.modules = ( "mod_rewrite", "mod_redire

我在FastCGI和Rails中遇到了一个令人沮丧的问题,lighttpd将路由url视为静态文件,即不将它们发送到Rails,因为它认为它们是静态的

如果我点击根路径,我会得到rails应用程序,但只要我点击了带有URL结构的内容,甚至是匹配默认:controller/:action路由的路径,我就会从lighttpd得到404,而rails应用程序甚至都不会被查询

这是我的lighttpd.conf:

server.modules = ( "mod_rewrite", "mod_redirect", "mod_access", "mod_status", "mod_fastcgi", "mod_accesslog" )

server.document-root = "/myapp/application/public"
index-file.names = ( "index.html", "dispatch.fcgi" )
server.error-handler-404 = "/myapp/application/public/404.html"

url.access-deny = ( "~", ".inc" )
server.pid-file = "/var/run/lighttpd.pid"
server.username = "lighttpd"
server.groupname = "lighttpd"

server.errorlog = "/var/log/lighttpd/error.log"
accesslog.filename = "/var/log/lighttpd/access.log"

#### fastcgi module
fastcgi.server = (
    ".fcgi" => (
        "myapp" => (
            "socket" => "/tmp/myapp.socket",
            "bin-path" => "/myapp/application/public/dispatch.fcgi",
            "check-local" => "disable",
            "fix-root-scriptname" => "true",
            "docroot"=>"/"
        )
    )
)

# mimetype mapping
mimetype.assign = (...)
至于错误,我一点也不知道。 尽管如此,如果我在Lighttpd中启用调试,我确实会看到如下事件:

2010-01-18 23:11:18: (response.c.261) URI-path     :  /tracking/index 
2010-01-18 23:11:18: (response.c.375) -- before doc_root 
2010-01-18 23:11:18: (response.c.376) Doc-Root     : /myapp/application/tracking/public 
2010-01-18 23:11:18: (response.c.377) Rel-Path     : /tracking/index 
2010-01-18 23:11:18: (response.c.378) Path         :  
2010-01-18 23:11:18: (response.c.426) -- after doc_root 
2010-01-18 23:11:18: (response.c.427) Doc-Root     : /myapp/application/tracking/public 
2010-01-18 23:11:18: (response.c.428) Rel-Path     : /tracking/index 
2010-01-18 23:11:18: (response.c.429) Path         : /myapp/application/tracking/public/tracking/index 
2010-01-18 23:11:18: (response.c.446) -- logical -> physical 
2010-01-18 23:11:18: (response.c.447) Doc-Root     : /myapp/application/tracking/public 
2010-01-18 23:11:18: (response.c.448) Rel-Path     : /tracking/index 
2010-01-18 23:11:18: (response.c.449) Path         : /myapp/application/tracking/public/tracking/index 
2010-01-18 23:11:18: (response.c.466) -- handling physical path 
2010-01-18 23:11:18: (response.c.467) Path         : /myapp/application/tracking/public/tracking/index 
2010-01-18 23:11:18: (response.c.523) -- file not found 
2010-01-18 23:11:18: (response.c.524) Path         : /myapp/application/tracking/public/tracking/index 
2010-01-18 23:11:18: (response.c.205) -- splitting Request-URI 
2010-01-18 23:11:18: (response.c.206) Request-URI  :  /myapp/application/tracking/public/404.html 

你知道哪里出了问题吗?

虽然文档没有真正解释server.error-handler设置的重要性,但还是有点像facepalm

使用fcgi时,需要确保错误处理程序设置为重定向到fcgi调度,否则,它只会显示404页面

server.error-handler-404 = "/dispatch.fcgi"

现在全部修复。

请注意,当使用server.error-handler-N时,您将错误页面视为完全限定的请求。它们向所有请求返回代码200。为了能够以正确的值返回带有错误代码的页面,您应该使用server.errorfile-prefix,在这里您可以声明一个包含html文件的文件夹,其中错误号为文件名,即404.html。