Nginx,FastCGI和Django连接拒绝错误

时间:2010-10-15 12:29:14

标签: django nginx fastcgi

我已经设置了nginx,fastcgi和django。通过fastcgi运行我的django项目:

python26 manage.py runfcgi host=127.0.0.1 port=8080 --settings=settings

当我访问http://127.0.0.1时,我可以看到正常的django 404,因为除了管理员之外我没有在我的django项目上设置所有内容。所以我尝试访问http://127.0.0.1/admin并返回502错误的网关错误。

我检查了日志,这是我发现的。有谁知道是什么导致了这个错误?

    2010/10/15 23:09:34 [error] 4796#0: *1 FastCGI sent in stderr: "" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /admin/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:8080", host: "localhost"
2010/10/15 23:09:34 [error] 4796#0: *1 FastCGI sent in stderr: "Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/flup/server/fcgi_base.py", line 574, in run
    protocolStatus, appStatus = self.server.handler(self)
  File "/usr/lib/python2.6/site-packages/flup/server/fcgi_base.py", line 1159, in handler
    result = self.application(environ, start_response)
  File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 245, in __call__
    response = middleware_method(request, response)
  File "/usr/lib/python2.6/site-packages/django/contrib/sessions/middleware.py", line 36, in process_response
    request.session.save()
  File "/usr/lib/python2.6/site-packages/django/contrib/sessions/backends/db.py", line 56, in save
    session_key = self.session_key,
  File "/usr/lib/python2.6/site-packages/django/contrib/sessions/backends/base.py", line 152, in _get_session_key
    self._session_key = self._get_new_session_key()
  File "/usr/lib/python2.6/site-packages/django/contrib/sessions/backends/base.py", line 144, in _get_new_session_key
    if not self.exists(session_key):
  File "/usr/lib/python2.6/site-packages/django/contrib/sessions/backends/db.py", line 29, in exists
    Session.objects.get(session_key=session_key)
  File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 132, in get
    return self.get_query_set().get(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 336, in get
    num = len(clone)
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 81, in __len__
    self._result_cache = list(self.iterator())
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 269, in iterator
    for row in compiler.results_iter():
  File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 672, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 726, in execute_sql
    cursor =

BTW我正在运行nginx07和django1.2。

更新:

这是我的nginx配置:

    user  apache apache;

worker_processes  4;

error_log /var/log/nginx/error_log info;

events {
    worker_connections  1024;
    use epoll;
}

http {
    include            /etc/nginx/mime.types;
    default_type    application/octet-stream;

    log_format main
        '$remote_addr - $remote_user [$time_local] '
            '"$request" $status $bytes_sent '
        '"$http_referer" "$http_user_agent" '
        '"$gzip_ratio"';

    client_header_timeout    10m;
    client_body_timeout        10m;
    send_timeout            10m;

    connection_pool_size        256;
    client_header_buffer_size    1k;
    large_client_header_buffers    4 2k;
    request_pool_size            4k;

    gzip on;
    gzip_min_length    1100;
    gzip_buffers    4 8k;
    gzip_types        text/plain;

    output_buffers    1 32k;
    postpone_output    1460;

    sendfile    on;
    tcp_nopush    on;
    tcp_nodelay    on;

    keepalive_timeout    75 20;

    ignore_invalid_headers    on;
    index index.html;

    server {
        listen 80;
        server_name localhost;
        location /site_media  {
            root /media/; # Notice this is the /media folder that we create above
        }
        location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov) {
            access_log   off;
            expires      30d; 
        }
        location / {
            # host and port to fastcgi server
            fastcgi_pass 127.0.0.1:8080;
            fastcgi_param  CONTENT_LENGTH   $content_length;
            fastcgi_param  CONTENT_TYPE     $content_type;
            fastcgi_param  PATH_INFO        $fastcgi_script_name;
            fastcgi_param  QUERY_STRING     $query_string;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  SERVER_NAME      $server_name;
            fastcgi_param  SERVER_PORT      $server_port;
            fastcgi_param  SERVER_PROTOCOL  $server_protocol;

            fastcgi_pass_header Authorization;
            fastcgi_intercept_errors off;
        }
        access_log    /var/log/nginx/localhost.access_log main;
        error_log    /var/log/nginx/localhost.error_log;
    }
}

1 个答案:

答案 0 :(得分:0)

我可以从你的日志中看到,即使连接'/'也被拒绝了,所以这与管理员没有任何关系。

尝试使用telnet连接到正确端口上的localhost,看看是否可以打开连接。我猜这个守护进程没有运行。

您还删除了python traceback,这对于确定进程可能崩溃的原因非常有帮助。