綠色資源網:您身邊(biān)最(zuì)放心的安全下載站(zhàn)! 最新軟(ruǎn)件|熱門排行|軟件分類|軟件專(zhuān)題|廠(chǎng)商(shāng)大全

綠色資源網

技術教程
您的(de)位置(zhì):首頁服務(wù)器類Web服(fú)務器 → nginx 502 bad gateway

nginx 502 bad gateway

我要評論 2012/11/29 20:51:25 來源:綠色資源網 編輯(jí):www.itseasyglobal.com [ ] 評論(lùn):0 點擊:227次(cì)

我們在使(shǐ)用(yòng)nginx的(de)時候有不少問題出現,首先我(wǒ)們就(jiù)來解決下nginx 502錯誤的問題

經(jīng) 過(guò)分析將(jiāng)nginx的error log打開(kāi),發現”pstream sent too big header while reading response header from upstream”這樣的錯誤提示,查閱了一下資料,大意是nginx緩衝區有一個bug造(zào)成的,我們網(wǎng)站的頁(yè)麵消耗占用(yòng)緩衝區可能(néng)過(guò)大

我們是nginx反(fǎn)向代理(lǐ)
proxy是nginx作為client轉發時使用的(de),如(rú)果header過大,超出(chū)了默認的1k,就會引發上述的upstream sent too big header (說白了就(jiù)是nginx把外部請求給後端apache ,apache返回的header  太大nginx處理不過來就導致了。

server {
        listen       80;
        server_name  *.xywy.com ;

       large_client_header_buffers 4 16k;

       #charset koi8-r;

       # access_log off;

       locations / {

#添(tiān)加這3行 ,
                proxy_buffer_size 64k;
                proxy_buffers   32 32k;
                proxy_busy_buffers_size 128k;

          proxy_set_header Host $host;
           proxy_set_header X-Real-IP       $remote_addr;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;

          set $baiduspider '';

          if ( $http_user_agent ~ Baiduspider) {
              set $baiduspider Baidu;
          }

............

如果是 nginx+PHPcgi 就該 

fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on
011/01/07 11:12:57 [error] 10770#0: *38585340 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 116.22.131.154, server: *.xywy.com, request: "GET /ysmp/index.php?did=124994 HTTP/1.0", upstream: "http://127.0.0.1:8080/ysmp/index.php?did=124994", host: "xywy.yn16.com"
 

後來原來那錯誤沒了出了新錯誤了 upstream timed out 超時?

server {
        listen       80;
        server_name  *.xywy.com ;
  large_client_header_buffers 4 16k;
        client_max_body_size 300m;
        client_body_buffer_size 128k;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_send_timeout 600;
                proxy_buffer_size 64k;
                proxy_buffers   4 32k;
                proxy_busy_buffers_size 64k;
            

關(guān)鍵詞(cí):nginx

閱讀本文後您有什(shí)麽(me)感想? 已有 人給(gěi)出(chū)評(píng)價!

  • 0 歡(huān)迎喜(xǐ)歡
  • 0 白(bái)癡
  • 0 拜托
  • 0 哇(wa)
  • 0 加油
  • 0 鄙視