2012-07-17 108 views
4

「而從上游讀取響應頭上游發送太大了頭」。我增加了我的緩衝區:nginx的大標題響應

proxy_buffer_size 256k; 
proxy_buffers 8 256k; 
proxy_busy_buffers_size 512k; 
fastcgi_buffers 8 256k; 
fastcgi_buffer_size 128k; 

但它似乎沒有幫助。有關爲什麼會發生這種情況的任何想法?

nginx.conf文件:

user www-data; 
worker_processes 1; 

error_log /var/log/nginx/error.log; 
pid  /var/run/nginx.pid; 

events { 
    worker_connections 1024; 
    # multi_accept on; 
} 


http { 
    include  /etc/nginx/mime.types; 

proxy_buffer_size 256k; 
proxy_buffers 8 256k; 
proxy_busy_buffers_size 512k; 
fastcgi_buffers 8 256k; 
fastcgi_buffer_size 128k; 

    access_log /var/log/nginx/access.log; 

    sendfile  on; 
    #tcp_nopush  on; 

    #keepalive_timeout 0; 
    keepalive_timeout 65; 
    tcp_nodelay  on; 

    gzip on; 
    gzip_disable "MSIE [1-6]\.(?!.*SV1)"; 

    include /etc/nginx/conf.d/*.conf; 
    include /etc/nginx/sites-enabled/*; 
} 

的/ etc/nginx的/啓用的站點 - /默認

server { 
    listen 80 default; 
    server_name localhost; 

    access_log /var/log/nginx/localhost.access.log; 

    location/{ 
     root /var/www/nginx-default; 
     index index.html index.htm; 
    } 

    location /doc { 
     root /usr/share; 
     autoindex on; 
     allow 127.0.0.1; 
     deny all; 
      } 

    location /images { 
     root /usr/share; 
     autoindex on; 
    } 
} 
+0

你作爲後端使用什麼樣的? – VBart 2012-07-17 21:12:56

+0

nginx。我以爲我已經提到過,看起來像我忘了。 – 2012-07-18 04:11:26

+0

你確定嗎? nginx如何從Facebook做認證? – VBart 2012-07-18 11:31:00

回答

1

原來Codeigniter設置了它自己的最大尺寸。我還沒有想出如何限制,但改變nginx不會改變任何東西,不幸的是。感謝所有幫助VBart和gsharma。

2

我今天早上有完全相同的問題。但是,增加緩衝區大小對我有效。這是我使用的設置:

proxy_buffer_size 128k; 
    proxy_buffers  4 256k; 
    proxy_busy_buffers_size 256k; 
    proxy_temp_file_write_size 256k; 

唯一設置我沒有看到在你的配置是

proxy_temp_file_write_size 256k; 

另外,我添加了這些值只是針對虛擬主機。我認爲這不重要,但可能值得嘗試。

11

在codeigniter中我有同樣的錯誤。這個工作對我來說:

http://forum.nginx.org/read.php?2,192785,196003#msg-196003

在.conf文件

location ~* \.php$ { 
    fastcgi_pass 127.0.0.1:9001; 
    fastcgi_index index.php; 
    fastcgi_split_path_info ^(.+\.php)(.*)$; 
    include fastcgi_params; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 

    # 16-sept-2012 parametros para evitar el 502 
    fastcgi_temp_file_write_size 10m; 
    fastcgi_busy_buffers_size 512k; 
    fastcgi_buffer_size 512k; 
    fastcgi_buffers 16 512k; 
    fastcgi_connect_timeout 300; 
    fastcgi_send_timeout 300; 
    fastcgi_read_timeout 300; 
    fastcgi_intercept_errors on; 
    fastcgi_next_upstream error invalid_header timeout http_500; 
} 
+1

我有同樣的問題,這個答案幫助。 – aarreoskari 2013-04-02 14:14:04

+0

這會對性能產生負面影響嗎? – DesignerGuy 2013-04-24 07:06:49

0

我收到此錯誤,頁面是800個字節長,4頭上。這是一個註銷頁面來刪除cookie。爲了過期cookies,我將它們設置回我的生日。這在nginx中不起作用,它們必須過期不到一個月才能通過驗證來刪除cookie。

我對另外幾個不同但卻無效的頭文件進行了檢查,得到了相同的結果。如果nginx的無法驗證它拋出標題:從體驗的詳細信息:上游發送太大的頭,一邊瀏覽上游

2015年響應頭 upstream sent too big header while reading response header from upstream是說:「我不喜歡我所看到的nginx的的通用方式「

  1. 上游服務器線程崩潰
  2. 上游服務器發送一個無效的頭回
  3. 的通知/發送來自STDERR回警告打破了他們的緩衝區,它和標準輸出被關閉

3:看看消息上方的錯誤日誌,它是否在消息前面記錄了行?PHP message: PHP Notice: Undefined index: 實例從一個循環我的日誌文件片段:

2015/11/23 10:30:02 [error] 32451#0: *580927 FastCGI sent in stderr: "PHP message: PHP Notice: Undefined index: Firstname in /srv/www/classes/data_convert.php on line 1090 
PHP message: PHP Notice: Undefined index: Lastname in /srv/www/classes/data_convert.php on line 1090 
... // 20 lines of same 
PHP message: PHP Notice: Undefined index: Firstname in /srv/www/classes/data_convert.php on line 1090 
PHP message: PHP Notice: Undefined index: Lastname in /srv/www/classes/data_convert.php on line 1090 
PHP message: PHP Notice: 
2015/11/23 10:30:02 [error] 32451#0: *580927 FastCGI sent in stderr: "ta_convert.php on line 1090 
PHP message: PHP Notice: Undefined index: Firstname 

您可以在3號線(從20個以前的錯誤)請參閱緩衝區限制被打,斷了,下一個線程寫在了它。然後Nginx關閉連接並返回502給客戶端。

2:記錄每個請求發送的所有頭文件,檢查它們並確保它們符合標準(nginx不允許超過24小時的任何內容刪除/過期cookie,發送無效的內容長度,因爲錯誤消息之前被緩存內容計數...)

實例包括:

<?php 
//expire cookie 
setcookie ('bookmark', '', strtotime('2012-01-01 00:00:00')); 
// nginx will refuse this header response, too far past to accept 
.... 
?> 

和此:

<?php 
header('Content-type: image/jpg'); 
?> 

<?php //a space was injected into the output above this line 
header('Content-length: ' . filesize('image.jpg')); 
echo file_get_contents('image.jpg'); 
// error! the response is now 1-byte longer than header!! 
?> 

1:驗證,或使一個SCRI pt日誌,以確保您的線程到達正確的終點,並在完成前不退出。

0

我們正在移動我們的生產環境,而舊的工作環境沒有問題,並且具有相同的「上游在讀取來自上游的響應標題時發送過大的標題」問題。這是一個Codeigniter 2.x應用程序。

就像@gsharma說的那樣,在更改服務器配置後,錯誤日誌消失了。

fastcgi_buffers 256 4k; 
    fastcgi_buffer_size 8k; 

然而,仍然有一些問題:登錄did'n工作了。 問題出現在$ config ['sess_encrypt_cookie'] = TRUE;

當使用sess_encrypt_cookie時,Codeigniter嘗試使用mcrypt庫,但如果它不存在,則使用名爲'_xor_encode'的方法。好吧,我認爲這種方法是越野車。

安裝php-mcrypt後,一切都沒問題。

(對不起,我的英語)