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

发布于 2024-08-18 05:17:21 字数 2781 浏览 0 评论 0原文

我遇到了 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 

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

I've come across a frustrating issue with FastCGI and Rails whereby lighttpd is treating routed url's as static files (i.e. not sending them to rails since it believes they're static)

If I hit the root path I get the rails application, but as soon as I hit something with a URL structure, even a path that matches the default :controller/:action route, I get a 404 from lighttpd and the rails app isn't even consulted.

Here's my 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 = (...)

As for errors, I don't get any at all.
Although, if I turn on debugging in Lighttpd, I do see events like these:

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 

Any ideas what could be going wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半窗疏影 2024-08-25 05:17:21

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

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

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

现在全部修好了。

Bit of a facepalm moment there although the documentation doesn't really explain the importance of the server.error-handler setting.

When using fcgi, you need to ensure your error-handler is set to redirect to the fcgi dispatch, else, it'll just show a 404 page.

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

All fixed now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文