1

我想用 Django 配置 Lighttpd 以显示在 localhost:3033 基本的“hello-world”Django 网站(由创建$ django-admin startproject hellodjango)。我遵循了文档,但我无法使我的网站正常工作。转到 localhost:3033 后什么都没有发生,我唯一看到的是消息“等待连接”。

我的lighttpd.config

server.groupname            = "www-data"

index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm",
                               " index.lighttpd.html" )

url.access-deny             = ( "~", ".inc" )

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

## Use ipv6 if available
#include_shell "/usr/share/lighttpd/use-ipv6.pl"

dir-listing.encoding        = "utf-8"
server.dir-listing          = "enable"

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/x-javascript", "text/css", "text/html", "text/plain" )

include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"


# My configuration
$HTTP["host"] == "www.hellodjango.com" {

    server.document-root = "/home/krris/programowanie/django/hellodjango"
    server.errorlog = "/home/krris/programowanie/django/hellodjango/logs/error.log"
    accesslog.filename = "/home/krris/programowanie/django/hellodjango/logs/access.log"
    fastcgi.server = (
        "/hellodjango.fcgi" => (
            "main" => (
                # Use host / port instead of socket for TCP fastcgi
                "host" => "127.0.0.1",
                "port" => 3033,
                # "socket" => "/home/krris/hellodjango.sock",
                "check-local" => "disable",
            )
        ),
    )
    alias.url = (
        "/media/" => "/home/krris/programowanie/django/hellodjango/media/",
    )

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

hellodjango.fcgi

#!/usr/bin/python
import sys, os

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

# Switch to the directory of your project. (Optional.)
os.chdir("/home/krris/programowanie/django/hellodjango")

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

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="prefork", daemonize="true", host="127.0.0.1", port="3033")

我还在settings.py 中添加了这一行:

FORCE_SCRIPT_NAME = ""

我使用命令运行我的应用程序:

$ ./manage.py runfcgi method=prefork host=127.0.0.1 port=3033

错误日志:

2013-03-19 11:27:10: (log.c.166) server started 
2013-03-19 11:27:16: (server.c.1396) [note] graceful shutdown started 
2013-03-19 11:27:16: (log.c.166) server started 
2013-03-19 11:27:16: (server.c.1512) server stopped by UID = 0 PID = 8093

我正在使用 Ubuntu 12.10。

4

2 回答 2

0

您的服务器由于某种原因停止。一种可能的调试方法是在此处设置 daemonize="false":

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

这可以帮助您了解正在发生的事情以及服务器关闭的原因。

于 2013-03-19T12:05:21.210 回答
0

我试过做你刚刚做的事情。我发现做这项工作的另一件事(我认为)是确保:

  • .fcgi 文件对每个人都有可执行权限。
  • 日志文件夹也必须具有权限。

我看到的只是项目文件夹的文件列表视图。这是你得到的吗?它也不适用于我的 www.helloDjango.com 网址。

如果您得到相同的结果,请告诉我。我还发现要获得一个基本的 hello world 页面真的很困难和令人困惑。

于 2013-04-24T09:01:05.423 回答