Django、lighttpd、FastCGI——无法让它工作

发布于 2024-10-19 06:12:39 字数 3362 浏览 3 评论 0原文

好的,我在尝试使用 FastCGI 在 lighttpd 上运行 Django 时遇到问题。我已按照此处的说明进行操作,但仍然无法获取它可以工作,但不确定问题是什么。

django 项目在使用 runserver 运行时确实可以工作。

因此,我启动 django:

python manage.py runfcgi socket=/var/run/django/django.sock pidfile=/var/run/django/django-fcgi.pid

lighttpd fastcgi 配置如下所示:

server.document-root        = "/srv/www/lighttpd/"

fastcgi.server = (
"/django" => (
        (
            "socket" => "/var/run/django/django.sock",
            "check-local" => "enable",
        )
    ),
)

alias.url = (
    "/static" => "/srv/www/lighttpd/static",
)

url.rewrite-once = (
    "^(/static.*)$" => "$1",
    "^(/.*)$" => "/django$1",
)

使用此配置(或者如果我将 fastcgi.server< 中的“/django”替换为“.fcgi”或“/django.fcgi”) /code> 和 url.rewrite-once)当尝试访问 //static< 中的文件)时,我总是收到 404 /code> 工作正常)。在 error.log 中,服务器似乎从未尝试过 FastCGI:

2011-02-24 16:18:00: (response.c.300) -- splitting Request-URI 
2011-02-24 16:18:00: (response.c.301) Request-URI  :  / 
2011-02-24 16:18:00: (response.c.302) URI-scheme   :  http 
2011-02-24 16:18:00: (response.c.303) URI-authority:  XXX.amazonaws.com 
2011-02-24 16:18:00: (response.c.304) URI-path     :  / 
2011-02-24 16:18:00: (response.c.305) URI-query    :   
2011-02-24 16:18:00: (response.c.300) -- splitting Request-URI 
2011-02-24 16:18:00: (response.c.301) Request-URI  :  /d.fcgi/ 
2011-02-24 16:18:00: (response.c.302) URI-scheme   :  http 
2011-02-24 16:18:00: (response.c.303) URI-authority:  XXX.amazonaws.com 
2011-02-24 16:18:00: (response.c.304) URI-path     :  /d.fcgi/ 
2011-02-24 16:18:00: (response.c.305) URI-query    :   
2011-02-24 16:18:00: (response.c.349) -- sanatising URI 
2011-02-24 16:18:00: (response.c.350) URI-path     :  /d.fcgi/ 
2011-02-24 16:18:00: (mod_access.c.135) -- mod_access_uri_handler called 
2011-02-24 16:18:00: (response.c.470) -- before doc_root 
2011-02-24 16:18:00: (response.c.471) Doc-Root     : /srv/www/lighttpd/ 
2011-02-24 16:18:00: (response.c.472) Rel-Path     : /d.fcgi/ 
2011-02-24 16:18:00: (response.c.473) Path         :  
2011-02-24 16:18:00: (response.c.521) -- after doc_root 
2011-02-24 16:18:00: (response.c.522) Doc-Root     : /srv/www/lighttpd/ 
2011-02-24 16:18:00: (response.c.523) Rel-Path     : /d.fcgi/ 
2011-02-24 16:18:00: (response.c.524) Path         : /srv/www/lighttpd/d.fcgi/ 
2011-02-24 16:18:00: (response.c.541) -- logical -> physical 
2011-02-24 16:18:00: (response.c.542) Doc-Root     : /srv/www/lighttpd/ 
2011-02-24 16:18:00: (response.c.543) Rel-Path     : /d.fcgi/ 
2011-02-24 16:18:00: (response.c.544) Path         : /srv/www/lighttpd/d.fcgi/ 
2011-02-24 16:18:00: (response.c.561) -- handling physical path 
2011-02-24 16:18:00: (response.c.562) Path         : /srv/www/lighttpd/d.fcgi/ 
2011-02-24 16:18:00: (response.c.618) -- file not found 
2011-02-24 16:18:00: (response.c.619) Path         : /srv/www/lighttpd/d.fcgi/ 

如果我将 fastcgi 条目设置为“/”,并省略 url.rewrite-once部分,django 进程确实被调用,但看起来传递的 URI 始终是“/”,因此对“/static”中内容的请求返回根视图的 HTML。

这是在 Amazon EC2 上,运行 Fedora Core 8。我什至从源代码安装了最新的 lighttpd 版本,而不是发行版中的旧版本。

OK, so I'm having issues trying to run Django on lighttpd with FastCGI. I've followed the instructions here, but still can't get it to work, and am not sure what the problem is.

The django project does work when running with runserver.

So, I start django:

python manage.py runfcgi socket=/var/run/django/django.sock pidfile=/var/run/django/django-fcgi.pid

The lighttpd fastcgi configuration looks like this:

server.document-root        = "/srv/www/lighttpd/"

fastcgi.server = (
"/django" => (
        (
            "socket" => "/var/run/django/django.sock",
            "check-local" => "enable",
        )
    ),
)

alias.url = (
    "/static" => "/srv/www/lighttpd/static",
)

url.rewrite-once = (
    "^(/static.*)$" => "$1",
    "^(/.*)$" => "/django$1",
)

With this configuration (or if I replace "/django" with, say, ".fcgi" or "/django.fcgi" in the fastcgi.server and url.rewrite-once) I always get a 404 when trying to access / (files in /static work fine). In error.log, it looks like the server isn't ever trying FastCGI:

2011-02-24 16:18:00: (response.c.300) -- splitting Request-URI 
2011-02-24 16:18:00: (response.c.301) Request-URI  :  / 
2011-02-24 16:18:00: (response.c.302) URI-scheme   :  http 
2011-02-24 16:18:00: (response.c.303) URI-authority:  XXX.amazonaws.com 
2011-02-24 16:18:00: (response.c.304) URI-path     :  / 
2011-02-24 16:18:00: (response.c.305) URI-query    :   
2011-02-24 16:18:00: (response.c.300) -- splitting Request-URI 
2011-02-24 16:18:00: (response.c.301) Request-URI  :  /d.fcgi/ 
2011-02-24 16:18:00: (response.c.302) URI-scheme   :  http 
2011-02-24 16:18:00: (response.c.303) URI-authority:  XXX.amazonaws.com 
2011-02-24 16:18:00: (response.c.304) URI-path     :  /d.fcgi/ 
2011-02-24 16:18:00: (response.c.305) URI-query    :   
2011-02-24 16:18:00: (response.c.349) -- sanatising URI 
2011-02-24 16:18:00: (response.c.350) URI-path     :  /d.fcgi/ 
2011-02-24 16:18:00: (mod_access.c.135) -- mod_access_uri_handler called 
2011-02-24 16:18:00: (response.c.470) -- before doc_root 
2011-02-24 16:18:00: (response.c.471) Doc-Root     : /srv/www/lighttpd/ 
2011-02-24 16:18:00: (response.c.472) Rel-Path     : /d.fcgi/ 
2011-02-24 16:18:00: (response.c.473) Path         :  
2011-02-24 16:18:00: (response.c.521) -- after doc_root 
2011-02-24 16:18:00: (response.c.522) Doc-Root     : /srv/www/lighttpd/ 
2011-02-24 16:18:00: (response.c.523) Rel-Path     : /d.fcgi/ 
2011-02-24 16:18:00: (response.c.524) Path         : /srv/www/lighttpd/d.fcgi/ 
2011-02-24 16:18:00: (response.c.541) -- logical -> physical 
2011-02-24 16:18:00: (response.c.542) Doc-Root     : /srv/www/lighttpd/ 
2011-02-24 16:18:00: (response.c.543) Rel-Path     : /d.fcgi/ 
2011-02-24 16:18:00: (response.c.544) Path         : /srv/www/lighttpd/d.fcgi/ 
2011-02-24 16:18:00: (response.c.561) -- handling physical path 
2011-02-24 16:18:00: (response.c.562) Path         : /srv/www/lighttpd/d.fcgi/ 
2011-02-24 16:18:00: (response.c.618) -- file not found 
2011-02-24 16:18:00: (response.c.619) Path         : /srv/www/lighttpd/d.fcgi/ 

If I set the fastcgi entry to "/", and omit the url.rewrite-once section, the django process does get called, but it looks like the URI passed is always "/", so requests for stuff in "/static" return the HTML of the root view.

This is on Amazon EC2, running Fedora Core 8. I've even installed the latest lighttpd version from source, instead of the old one in the distribution.

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

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

发布评论

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

评论(1

神仙妹妹 2024-10-26 06:12:39

如上面的评论所示,“check-local”需要设置为“disabled”。

As in the comment above, "check-local" needs to be set to "disabled".

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