使用lighttpd、django和fastcgi时的URL问题

发布于 2024-09-13 13:43:14 字数 1379 浏览 4 评论 0 原文

我刚刚为 django 设置了 lighty 的 fastcgi,但是在处理 url 时我得到了 fcgi 文件路径,例如 http://myserver.myhost.com/myproject.fcgi。它需要路由到 / 而不是 /myproject.fcgi。

Lightyconf:

$HTTP["host"] =~ "myproject\.myhost\.com" {
        fastcgi.server = (
         ".fcgi" => (
           "localhost" => (
             "bin-path" => "/var/www/myproject/myproject.fcgi",
             "socket" => "/tmp/myproject.sock",
             "check-local" => "disable",
             "min-procs" => 2,
             "max-procs" => 4,
          )
        ),
)

        alias.url = (
            "/media" => "/usr/local/lib/python1.6/dist-packages/Django-1.2.1-py2.6.egg/django/contrib/admin/media/",
        )

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

myproject.fcgi:

#!/usr/bin/python2.6
import sys, os

# Add a custom Python path.
sys.path.insert(0, "..")

# Switch to the directory of your project. (Optional.)
os.chdir("/var/www/myproject")

os.environ['DJANGO_SETTINGS_MODULE'] = "settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(["method=threaded", "daemonize=false"])

I just set up fastcgi with lighty for django, but I'm getting the fcgi file path when it processes the url, e.g. 404 error at http://myserver.myhost.com/myproject.fcgi. It needs to route to / instead of /myproject.fcgi.

Lighty conf:

$HTTP["host"] =~ "myproject\.myhost\.com" {
        fastcgi.server = (
         ".fcgi" => (
           "localhost" => (
             "bin-path" => "/var/www/myproject/myproject.fcgi",
             "socket" => "/tmp/myproject.sock",
             "check-local" => "disable",
             "min-procs" => 2,
             "max-procs" => 4,
          )
        ),
)

        alias.url = (
            "/media" => "/usr/local/lib/python1.6/dist-packages/Django-1.2.1-py2.6.egg/django/contrib/admin/media/",
        )

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

myproject.fcgi:

#!/usr/bin/python2.6
import sys, os

# Add a custom Python path.
sys.path.insert(0, "..")

# Switch to the directory of your project. (Optional.)
os.chdir("/var/www/myproject")

os.environ['DJANGO_SETTINGS_MODULE'] = "settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(["method=threaded", "daemonize=false"])

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

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

发布评论

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

评论(1

戏蝶舞 2024-09-20 13:43:14

我再次回答我自己的问题。将其放入settings.py

FORCE_SCRIPT_NAME = ""

Once again I answer my own question. Put this into settings.py

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