![](/img/trans.png)
[英]LEMP PHP-FPM not working with nginx on ubuntu 10.04 White Screen
[英]Random “502 Error Bad Gateway” in Amazon Red Hat (Not Ubuntu) - Nginx + PHP-FPM
首先,我已經在Stackoverflow中搜索502錯誤。 有很多線程,但是這次的區別是該錯誤沒有模式出現,並且不在Ubuntu中。
一切正常,但我的網站每周大約顯示一次: 502 Bad Gateway 。 在出現第一個錯誤之后,每個連接開始顯示此消息。 重新啟動MySQL + PHP-FPM + Nginx + Varnish無法正常工作。
我必須克隆該實例,然后再創建一個,以重新啟動我的站點(該站點托管在Amazon EC2中)。
在Nginx日志中,它一次又一次顯示以下行:
[error] 16773#0: *7034 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1
MySQL或Varnish日志中沒有任何內容。 但是在PHP-FPM中,它顯示了這些行的類型:
WARNING: [pool www] child 18978, script '/var/www/mysite.com/index.php' (request: "GET /index.php") executing too slow (10.303579 sec), logging
WARNING: [pool www] child 18978, script '/var/www/mysite.com/index.php' (request: "GET /index.php") execution timed out (16.971086 sec), terminating
在PHP-FPM慢日志中,它顯示:
[pool www] pid 20401
script_filename = /var/www/mysite.com/index.php
w3_require_once() /var/www/mysite.com/wp-content/plugins/w3-total-cache/inc/define.php:1478
(在第1478行的文件“ define.php”中,它具有以下代碼行: require_once $ path; )
我認為問題出在W3 Total Cache插件上。 所以我刪除了W3 Total Cache。 大約5天后,它再次發生,並在PHP-FPM慢日志中出現此錯誤:
script_filename = /var/www/mysite.com/index.php
wpcf7_load_modules() /var/www/mysite.com/wp-content/plugins/contact-form-7/includes/functions.php:283
(在第283行的“ functions.php”文件中,具有以下代碼行: include_once $ file; )
前幾天,第一個錯誤發生在另一部分:
script_filename = /var/www/mysite.com/wp-cron.php
curl_exec() /var/www/mysite.com/wp-includes/class-http.php:1510
再次是代碼的不同部分:
[pool www] pid 20509
script_filename = /var/www/mysite.com/index.php
mysql_query() /var/www/mysite.com/wp-includes/wp-db.php:1655
CPU,RAM ...發生此錯誤時,一切都穩定(使用率不到20%)。
我嘗試了一切,但沒有任何效果:
自5個月前以來,每周大約都會發生這種情況。 我很絕望。 我要指出的是,我甚至將Nginx和PHP-FPM放在Linux的crontab中,以便每天重新啟動這些服務。 但這也沒有用。
有人對我可以解決這個問題有什么建議嗎? 一切都會幫助!
服務器:
Amazon c3.large (2 core and 3.75GB RAM)
Linux Amazon Red Hat 4.8.2 64bits
PHP-FPM:
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
listen.mode = 0664
pm = ondemand
pm.max_children = 480
pm.start_servers = 140
pm.min_spare_servers =140
pm.max_spare_servers = 250
pm.max_requests = 50
request_terminate_timeout = 15s
request_slowlog_timeout = 10s
php_admin_flag[log_errors] = on
Nginx:
worker_processes 2;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
types_hash_max_size 2048;
server_tokens off;
client_max_body_size 8m;
reset_timedout_connection on;
index index.php index.html index.htm;
keepalive_timeout 1;
proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
fastcgi_send_timeout 30s;
fastcgi_read_timeout 30s;
listen 127.0.0.1:8080;
location ~ .php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_keep_conn on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param HTTP_HOST $host;
}
}
我將從調整一些配置參數開始。
我認為您的pm值有些偏離,比我通常在您的規格上在服務器上看到的配置要高一些……但是您說內存消耗是正常的,所以有點奇怪。
無論如何...對於pm.max_children = 480
,考慮到默認情況下WordPress將內存限制增加到40MB,您最終將使用多達18個內存,因此您肯定想降低它。
請查看此帖子的第四部分,以獲取有關該信息的更多信息: http : //www.if-not-true-then-false.com/2011/nginx-and-php-fpm-configuration-and-optimizing-tips-and -技巧/
如果您使用的是Nginx,MySQL,Varnish和其他服務的512MB,則php-fpm大約為3328 MB,每個進程除以40 MB, pm.max_children
應該為80。 。但是即使是80也很高。
您也可能會降低pm.start_servers
, pm.min_spare_servers
和pm.max_spare_servers
的值。 我寧願將它們保持在較低水平,而僅增加它們的必要
對於pm.max_requests
,應保持默認值500,以避免服務器重生。 我認為只有在懷疑內存泄漏時才建議降低它。
將keepalive_timeout
更改為60,以更好地利用keep live。
除此之外,我認為一切看起來都很正常。
我在Ubuntu上遇到了這個問題,但是PHP-FPM上的request_terminate_timeout
和fastcgi_send_timeout
+ fastcgi_read_timeout
足以解決這個問題。
希望您能解決!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.