Lighttpd 中的 Django + Ubuntu 上的 FCGI - 当我启用第二个站点时重写停止工作

发布于 2024-07-24 14:32:14 字数 1787 浏览 2 评论 0原文

我已经将 lighttp 配置为在 ubuntu 上通过 fastcgi 启动和服务 django。 当我只启用一个站点时(通过 ubuntu 的类似 apache 的conf-available、conf-enabled 机制),一切都运行得很好。 当我启用第二个站点时,尽管 fcgi 进程已启动并提供数据,但我的 url 重写似乎无法正常工作。 这是我的配置:

conf-available/10-example.conf

$HTTP["host"] == "example.com" {
    var.virt_name = "example"
    include "includes/incl-fastcgi.conf"
}

includes/incl-fastcgi.conf

global {
    server.modules += ("mod_rewrite",
                   "mod_fastcgi")
}

var.site_folder = "/" + virt_name
var.site_root = server_root + site_folder
var.socket = server_root + "/.handles/" + virt_name + ".socket"
server.document-root = site_root

fastcgi.server = (
    "/django.fcgi" => (
        "main" => (
            "socket" => socket,
            "bin-path" => "/etc/lighttpd/scripts/fcgi.sh",
            "bin-environment" => ( "VIRT" => virt_name, ),
            "check-local" => "disable",
            "min-procs" => 1,
            "max-procs" => 1,
            "allow-x-send-file" => "enable",
        ),
    ),
)

alias.url = (
    "/media/admin" => "/usr/share/python-support/python-django/django/contrib/admin/media", #why the hell does it live here?
)

url.rewrite-once = (
    "^(/media.*)$" => "$1",
    "^/favicon\.ico$" => "/media/favicon.ico",
    "^/robots\.txt$" => "/robots.txt",
    "^(/.*)$" => "/django.fcgi$1",
)

当我启用第二个站点时,一切都相同,只是现在有第二个站点链接到启用conf 的10-example.conf 副本(稍作修改)。 发生这种情况时,我的网站会因以下 django-served 错误而失败:

Page not found (404)
Request Method:     GET
Request URL:    http://example.com/django.fcgi/[the url I requested]

我不确定为什么启用另一个网站会破坏现有设置。 我相信基于主机的语法应该隔离对该特定主机的任何更改,但情况似乎并非如此。

I've got lighttp configured to start and serve django via fastcgi on ubuntu. When I have only a single site enabled (via ubuntu's apache-like conf-available, conf-enabled mechanism), everything runs beautifully. When I enable a second site, my url rewrites seem to stop working correctly, though the fcgi processes are started and serving data. Here's my configuration:

conf-available/10-example.conf

$HTTP["host"] == "example.com" {
    var.virt_name = "example"
    include "includes/incl-fastcgi.conf"
}

includes/incl-fastcgi.conf

global {
    server.modules += ("mod_rewrite",
                   "mod_fastcgi")
}

var.site_folder = "/" + virt_name
var.site_root = server_root + site_folder
var.socket = server_root + "/.handles/" + virt_name + ".socket"
server.document-root = site_root

fastcgi.server = (
    "/django.fcgi" => (
        "main" => (
            "socket" => socket,
            "bin-path" => "/etc/lighttpd/scripts/fcgi.sh",
            "bin-environment" => ( "VIRT" => virt_name, ),
            "check-local" => "disable",
            "min-procs" => 1,
            "max-procs" => 1,
            "allow-x-send-file" => "enable",
        ),
    ),
)

alias.url = (
    "/media/admin" => "/usr/share/python-support/python-django/django/contrib/admin/media", #why the hell does it live here?
)

url.rewrite-once = (
    "^(/media.*)$" => "$1",
    "^/favicon\.ico$" => "/media/favicon.ico",
    "^/robots\.txt$" => "/robots.txt",
    "^(/.*)$" => "/django.fcgi$1",
)

When I enable the second site, everything is identical except that now there's a second link to a (slightly modified) copy of 10-example.conf in conf-enabled. When this happens, my sites fail with this django-served error:

Page not found (404)
Request Method:     GET
Request URL:    http://example.com/django.fcgi/[the url I requested]

I'm not sure why enabling another site should break the existing setup. I believe the host-based syntax should isolate any changes to that specific host, but it does not seem to be the case.

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

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

发布评论

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

评论(2

木格 2024-07-31 14:32:14

如果将来有人看到这个问题,我相信答案是它已在 1.4.20 或更高版本中修复,并且服务器正在运行 v1.4.19,因为这是 Ubuntu 的存储库所拥有的。

In case anyone in the future looks at this question, I believe the answer was that it's fixed in version 1.4.20 or later and the server was running v1.4.19 since that's what Ubuntu's repository had.

债姬 2024-07-31 14:32:14

您是否在设置中将 FORCE_SCRIPT_NAME 设置为“” .py?

FORCE_SCRIPT_NAME=""

Did you set FORCE_SCRIPT_NAME to "" in settings.py?

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