Django lighttpd FCGI错误

发布于 2024-10-17 01:48:40 字数 1505 浏览 1 评论 0原文

我正在尝试通过lighttpd + fcgi部署我的django应用程序,但是当我运行fcgi脚本时,它给了我一个错误

这是fcgi脚本本身:

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

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

# Switch to the directory of your project. (Optional.)
os.chdir("/home/wite/dormcode")

# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "dormcode.settings"

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

当使用python运行fcgi脚本时,我得到一个302 FOUND.当我尝试通过网络浏览器访问该页面时,我什么也没得到。

WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Status: 302 FOUND
Vary: Cookie
Content-Type: text/html; charset=utf-8
Location: http://localhost/login/
Set-Cookie:  csrftoken=30f07d4a59820a5ab7b502447cc16f5a; Max-Age=31449600; Path=/

*编辑*

在尝试了一些lighttpd配置选项后,我设法得到了一些不同的东西。当我通过网络浏览器访问该应用程序时,页面挂起一段时间并显示 500 错误,并将其保留在日志中:

2011-02-12 01:04:59: (mod_fastcgi.c.2582) unexpected end-of-file (perhaps the fastcgi process died): pid: 0 socket: tcp:127.0.0.1:80 
2011-02-12 01:04:59: (mod_fastcgi.c.3367) response not received, request sent: 1076 on socket: tcp:127.0.0.1:80 for /dormcode.fcgi?, closing connection

I am trying to deploy my django app via lighttpd + fcgi, but when I run the fcgi script, it gives me an error

Here's the fcgi script itself:

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

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

# Switch to the directory of your project. (Optional.)
os.chdir("/home/wite/dormcode")

# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "dormcode.settings"

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

When running the fcgi script with python, I get a 302 FOUND. When I try to go to the page via a web browser, I get nothing.

WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Status: 302 FOUND
Vary: Cookie
Content-Type: text/html; charset=utf-8
Location: http://localhost/login/
Set-Cookie:  csrftoken=30f07d4a59820a5ab7b502447cc16f5a; Max-Age=31449600; Path=/

*EDIT *

After playing around with some of the lighttpd configuration options, I managed to get something different. When I go to the app via the web browser, the page hangs for a while and turns up with a 500 Error, leaving this in the logs:

2011-02-12 01:04:59: (mod_fastcgi.c.2582) unexpected end-of-file (perhaps the fastcgi process died): pid: 0 socket: tcp:127.0.0.1:80 
2011-02-12 01:04:59: (mod_fastcgi.c.3367) response not received, request sent: 1076 on socket: tcp:127.0.0.1:80 for /dormcode.fcgi?, closing connection

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

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

发布评论

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

评论(2

请爱~陌生人 2024-10-24 01:48:40

这里面的内容远比表面上看到的还要多。

payne 是正确的,因为这个 fastcgi 监听器使用 stdin 作为其通信套接字。

然而,这只是运行 FastCGI 响应程序的一种方法。事实上,这是运行 lighttpd 响应程序的错误方法,因为 lighttpd 不支持通过 stdin 与其响应程序对话。

关键在于这一行:

runfastcgi(method="threaded", daemonize="false")

对于apache来说这是正确的行,但对于lighttpd来说不是正确的行。对于 lighttpd,您想要这样的东西:

runfastcgi(method="prefork", daemonize="true", host="127.0.0.1", port="3033")

这将做的是在您选择的主机/端口上运行 fastcgi 进程,作为将分叉到后台的守护进程。设置 daemonize="false" 进行调试,或者使用类似 supervisord 的东西,但大多数人通常想要一个守护进程。

应该注意的是,如果您的脚本与刚刚粘贴的脚本一样简单,则不需要整个脚本。您可以只通过manage.py运行fastCGI响应器:

./manage.py runfcgi method=prefork host=127.0.0.1 port=3033 pidfile=/path/to/foo.pid

现在您(希望)已经运行了FastCGI响应器,您想在lighttpd配置中执行此操作:

"/mysite.fcgi" => (
    "main" => (
         "host" => "127.0.0.1",
         "port" => 3033,
          "check-local" => "disable",
    )
),

也就是说,无论您为fastcgi响应器选择什么端口,您需要将 lighttpd 指向那里。

应该注意的是,所有这些都可以在 Django FastCGI 文档,但由于开源项目中的频繁编辑和一些功能的扩展,该文档已经失去了很多清晰度。

There's more to this than meets the eye.

payne is correct in that this fastcgi listener is using stdin as its socket for communication.

However, this is just one of the ways to run a FastCGI responder. In fact, it's the incorrect way to run a responder for lighttpd, because lighttpd does not support talking to its responders via stdin.

The key lies in this line:

runfastcgi(method="threaded", daemonize="false")

This is the correct line for apache, but not the correct line for lighttpd. For lighttpd, you want something like this:

runfastcgi(method="prefork", daemonize="true", host="127.0.0.1", port="3033")

What this will do is run the fastcgi process instead on a host/port of your choosing, as a daemon which will fork to the background. Set daemonize="false" for debugging, or if using something like supervisord but most people generally want a daemon.

It should be noted that the entire script is not necessary if your script is as simple as the one you just pasted. You can instead just run the fastCGI responder through manage.py:

./manage.py runfcgi method=prefork host=127.0.0.1 port=3033 pidfile=/path/to/foo.pid

Now that you've (hopefully) got your FastCGI responder running, you want to do this in your lighttpd config:

"/mysite.fcgi" => (
    "main" => (
         "host" => "127.0.0.1",
         "port" => 3033,
          "check-local" => "disable",
    )
),

That is, whatever port you choose for your fastcgi responder, you need to point lighttpd there.

It should be noted that all of this is available in the Django FastCGI documentation but this documentation has lost much of its clarity through frequent edits and some amount of feature creep in an open source project.

南烟 2024-10-24 01:48:40

首先,使用 sh 您尝试将脚本作为 shell 脚本运行,而不是 Python 程序。如果您确实想将其作为 python 程序运行,请输入 python /home/wite/code/code.fcgi

其次,请记住 FastCGI 应用程序作为守护程序运行 - 您仍然需要一个 Web 服务器连接到您在此处开始的流程。

最后,如果您尝试手动测试此 FastCGI 程序:这并不总是有帮助,因为 FastCGI 在 Web 服务器和应用程序之间的 stdin 和 stdout 上使用特殊协议。 (您可以通过这种方式测试 CGI 脚本,因为 CGI 更简单)。

First, with sh you're trying to run your script as a shell script, not a Python program. If you really want to run it as a python program, type python /home/wite/code/code.fcgi

Second, keep in mind that FastCGI apps run as deamons -- you still need a Web server to connect to the process you're starting here.

Finally, if you're trying to test this FastCGI program by hand: this isn't always helpful, because FastCGI uses a special protocol on stdin and stdout between the Web server and your application. (You could test CGI scripts this way because CGI was much simpler).

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