【问题标题】:Lighttpd/FastCGI treating routes as static contentLighttpd/FastCGI 将路由视为静态内容
【发布时间】:2011-01-06 08:27:22
【问题描述】:

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

如果我点击根路径,我会得到 rails 应用程序,但是一旦我遇到带有 URL 结构的东西,即使是与默认 :controller/:action 路由匹配的路径,我也会从 lighttpd 和 rails 得到 404应用程序甚至没有被咨询。

这是我的 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 

有什么想法可能会出错吗?

【问题讨论】:

    标签: ruby-on-rails fastcgi lighttpd


    【解决方案1】:

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

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

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

    现在全部修复。

    【讨论】:

    • 请注意,当使用“server.error-handler-N”时,您将错误页面视为完全限定的请求。他们向所有请求返回代码“200”。为了真正能够通过正确的值返回带有错误代码的页面,您应该使用“server.errorfile-prefix”,在其中声明一个包含 html 文件的文件夹,并将错误编号作为文件名(即“404.html”)。跨度>
    猜你喜欢
    • 2022-11-25
    • 1970-01-01
    • 2018-11-26
    • 1970-01-01
    • 1970-01-01
    • 2011-01-04
    • 1970-01-01
    • 2014-08-13
    • 2016-07-16
    相关资源
    最近更新 更多