2008-10-01 86 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使用地址空間的方式,這可能是一個硬性限制。