1. 程式人生 > 其它 >[Nginx] 部落格園出現了502錯誤該怎麼追查原因

[Nginx] 部落格園出現了502錯誤該怎麼追查原因

技術標籤:資料庫javanginxlinuxmysql

部落格園從今天上午就開始報502錯誤 , 他的原因還不知道 , 暫時先說下我們遇到502的排查情況

最大的可能性就是後端的服務不能支撐前端過來的tcp請求連線,包括連線資料庫服務時的連線數問題

1. php-fpm的程序是否啟動 ,沒啟動肯定報這個錯誤

2. tcp連線數超過了fpm的程序數

netstat -altupn|grep EST|grep php|wc -l

檢視當前tcp連線 , 比較自己fpm的程序數

修改配置檔案中的程序數部分:

/etc/php-fpm.d/www.conf

; Note: This value is mandatory.
pm = dynamic

; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes to be created when pm is set to 'dynamic'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI.
; Note: Used when pm is set to either 'static' or 'dynamic'
; Note: This value is mandatory.
pm.max_children = 200

; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 30

; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 10

; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 50

3.FastCGI執行時間過長


根據實際情況調高以下引數值
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;

4.FastCGI Buffer不夠
nginx和apache一樣,有前端緩衝限制,可以調整緩衝引數
fastcgi_buffer_size 32k;
fastcgi_buffers 8 32k;

5.Proxy Buffer不夠
如果你用了Proxying,調整
proxy_buffer_size 16k;
proxy_buffers 4 16k;

程式碼中有連線資料庫等的錯誤 , 導致執行時間過長了 , 檢查程式碼等