2008-10-01 88 views
10

我使用fastcgi接口运行Django站点到nginx。但是,有些页面被截断(即页面源停止,有时位于标签的中间)。我该如何解决这个问题(让我知道需要什么额外的信息,我将它张贴)Nginx + fastcgi截断问题

详情:

我使用flup,并用以下命令产卵FastCGI的服务器:

python ./manage.py runfcgi umask=000 maxchildren=5 maxspare=1 minspare=0 method=prefork socket=/path/to/runfiles/django.sock pidfile=/path/to/runfiles/django.pid 

nginx的配置如下:

# search and replace this: {project_location} 
pid /path/to/runfiles/nginx.pid; 
worker_processes 2; 
error_log /path/to/runfiles/error_log; 
events { 
    worker_connections 1024; 
    use epoll; 
} 
http { 
    # default nginx location 
    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 3m; 
    client_body_timeout 3m; 
    send_timeout   3m; 
    connection_pool_size  256; 
    client_header_buffer_size 1k; 
    large_client_header_buffers 4 2k; 
    request_pool_size  4k; 
    output_buffers 4 32k; 
    postpone_output 1460; 
    sendfile  on; 
    tcp_nopush    on; 
    keepalive_timeout  75 20; 
    tcp_nodelay   on; 
    client_max_body_size  10m; 
    client_body_buffer_size 256k; 
    proxy_connect_timeout  90; 
    proxy_send_timeout   90; 
    proxy_read_timeout   90; 
    client_body_temp_path  /path/to/runfiles/client_body_temp; 
    proxy_temp_path   /path/to/runfiles/proxy_temp; 
    fastcgi_temp_path   /path/to/runfiles/fastcgi_temp; 
    gzip on; 
    gzip_min_length 1100; 
    gzip_buffers  4 32k; 
    gzip_types  text/plain text/html application/x-javascript text/xml text/css; 
    ignore_invalid_headers on; 
    server { 
     listen 80; 
     server_name alpha2.sonyalabs.com; 
     index index.html; 
     root /path/to/django-root/static; 
     # static resources 
     location ~* ^/static/.*$ 
     { 
     root /path/to/django-root; 
       expires 30d; 
       break; 
     } 
     location/{ 
      # host and port to fastcgi server 
      fastcgi_pass unix:/path/to/runfiles/django.sock; 
      fastcgi_param PATH_INFO $fastcgi_script_name; 
      fastcgi_param REQUEST_METHOD $request_method; 
      fastcgi_param QUERY_STRING $query_string; 
      fastcgi_param CONTENT_TYPE $content_type; 
      fastcgi_param CONTENT_LENGTH $content_length; 
      fastcgi_pass_header Authorization; 
      fastcgi_intercept_errors off; 
     } 
     location /403.html { 
       root /usr/local/nginx; 
       access_log off; 
     } 
     location /401.html { 
       root /usr/local/nginx; 
       access_log off; 
     } 
     location /404.html { 
       root /usr/local/nginx; 
       access_log off; 
     } 
     location = /_.gif { 
        empty_gif; 
       access_log off; 
     } 
      access_log /path/to/runfiles/localhost.access_log main; 
      error_log /path/to/runfiles/localhost.error_log; 
     } 
} 

回答

3

什么FastCGI的接口,您使用以及如何。它是否是flup?如果是的话,粘贴你产生服务器的方式,以及它是如何挂钩到nginx的。没有这些信息,它只是猜测可能会出现什么问题。

可能出现的问题:

  • nginx的是越野车。至少有lighttpd的FastCGI的可怕的错误,如果Nginx已经我也不会惊讶的是有些太:)
  • Django是死亡与内部系统的跟踪信息是不正确获取,并关闭FastCGI的服务器,你不能从看客户端。在这种情况下,包装fastcgi服务器应用程序调用并尝试/除了它打印异常。

但服务器日志和配置将是巨大的。

+0

我更新了更多信息的描述 - 你介意看看并告诉我你看到了什么? – Silas 2008-10-02 01:26:30

+0

Armin,你会介意在nginx和lighttpd中发布有关FastCGI错误的信息吗?在这个网站上,“Apache或lighttpd”和“最干净&最快的Django服务器设置”可以使用这些知识。 – akaihola 2008-10-06 08:48:20

0

我都在我的虚拟主机提供商(Webfaction)和一个本地的Ubuntu开发服务器上运行的非常相似的配置,这一点,我看不出有什么问题。我猜这是一个超时或完整的缓冲区,造成这种情况。

你可以发布nginx错误日志的输出吗?你使用的是什么版本的nginx?

作为一个侧面说明,它可能是值得考虑的django-logging找出你的FastCGI进程正在做什么。

5

检查错误日志“权限被拒绝”的错误写.../nginx/tmp/...文件。除非需要临时空间,Nginx会正常工作,并且通常发生在32K边界。如果发现这些错误,请确保tmp目录可由用户nginx运行时写入。

7

我在nginx上运行Nagios的确切问题是一样的。我偶然发现了你的问题,而谷歌搜索的答案,并读取“权限被拒绝”的相关答案,忽然想起(也许它会帮助你):

  • Nginx的错误。日志发布:

    2011/03/07 11:36:02 [crit] 30977#0:* 225952 open()“/ var/lib/nginx/fastcgi/2/65/0000002652”failed(13:权限被拒绝)

  • 所以我只是跑#乔敦 - R的WWW的数据:WWW的数据的/ var/lib中/ nginx的/ FastCGI的

  • 固定! (并感谢您的间接帮助)

2

FastCGI不是为此责怪。

我遇到了完全相同的问题,使用nginx/gunicorn。将响应大小减少到32k以下(在特定情况下,使用模板中的spaceless标记)可以解决此问题。

正如dwc所说,由于nginx使用地址空间的方式,这可能是一个硬性限制。