{"id":115176,"date":"2018-08-10T08:02:20","date_gmt":"2018-08-10T00:02:20","guid":{"rendered":"https:\/\/gulass.cn\/?p=115176"},"modified":"2018-08-06T10:07:42","modified_gmt":"2018-08-06T02:07:42","slug":"502-bad-gateways","status":"publish","type":"post","link":"https:\/\/gulass.cn\/502-bad-gateways.html","title":{"rendered":"\u9519\u8bef\u89e3\u51b3\uff1aNginx php-fpm 502 bad gateways"},"content":{"rendered":"
\u73af\u5883\uff1a<\/p>\n
Ubuntu 16.04.2<\/p>\n
nginx version: nginx\/1.10.3 (Ubuntu)<\/p>\n
php-fpm version: php-fpm\/5.6<\/p>\n
\r\nWARNING: [pool www] server reached pm.max_children setting (5), consider raising it\r\n<\/pre>\nNginx\u9519\u8bef\u65e5\u5fd7<\/strong><\/span><\/div>\n\r\neader from upstream, client: xxx.xxx.xxxx.xxx, server: xxx.domain.com, request: \"GET \/index.php\/1\/2\/test.html HTTP\/1.0\", upstream: \"fastcgi:\/\/unix:\/run\/php\/php5.6-fpm.sock:\", host: \"xxx.domain.com\", referrer: \"http:\/\/xxx.domain.com.\/index.php\/1\/2\/test.html?filter_limit=100\"\r\n<\/pre>\n\u4eceNginx\u65e5\u5fd7\u91cc\u9762\u5f88\u5bb9\u6613\u770b\u51fa\u6765\uff0c\u662fphp-fpm\u51fa\u4e86\u95ee\u9898\uff0c\u91cd\u542fphp-fpm\u540e\u7f51\u7ad9\u6062\u590d\u6b63\u5e38\u3002php-fpm\u65e5\u5fd7\u91cc\u9762\u7ed9\u51fa\u4e86\u8be6\u7ec6\u7684\u9519\u8bef\u63d0\u793a\uff0c\u5b50\u8fdb\u7a0b\u6570\u5df2\u7ecf\u8fbe\u5230\u8bbe\u7f6e\u7684\u6700\u5927\u503c\u3002 <\/p>\n
\u89e3\u51b3\u65b9\u6848<\/strong><\/span><\/div>\n\r\n\/etc\/php\/5.6\/fpm\/php-fpm.conf\r\n\/etc\/php\/5.6\/fpm\/pool.d\/www.conf\r\n<\/pre>\n\u5b9a\u4f4d\u81f3\u914d\u7f6e\u6587\u4ef6\uff0c\u67e5\u627epm.max_children\u9879 \uff085.6\u7248\u672c\u5728www.conf\u4e2d\uff09<\/p>\n
\r\n...\r\n pm = dynamic #\u5bf9\u4e8e\u4e13\u7528\u670d\u52a1\u5668\uff0cpm\u53ef\u4ee5\u8bbe\u7f6e\u4e3astatic\u3002\r\n #\u5982\u4f55\u63a7\u5236\u5b50\u8fdb\u7a0b\uff0c\u9009\u9879\u6709static\u548cdynamic\u3002\u5982\u679c\u9009\u62e9static\uff0c\u5219\u7531pm.max_children\u6307\u5b9a\u56fa\u5b9a\u7684\u5b50\u8fdb\u7a0b\u6570\u3002\u5982\u679c\u9009\u62e9dynamic\uff0c\u5219\u7531\u4e0b\u5f00 \u53c2\u6570\u51b3\u5b9a\uff1a\r\n pm.max_children #\uff0c\u5b50\u8fdb\u7a0b\u6700\u5927\u6570\r\n pm.start_servers #\uff0c\u542f\u52a8\u65f6\u7684\u8fdb\u7a0b\u6570\r\n pm.min_spare_servers #\uff0c\u4fdd\u8bc1\u7a7a\u95f2\u8fdb\u7a0b\u6570\u6700\u5c0f\u503c\uff0c\u5982\u679c\u7a7a\u95f2\u8fdb\u7a0b\u5c0f\u4e8e\u6b64\u503c\uff0c\u5219\u521b\u5efa\u65b0\u7684\u5b50\u8fdb\u7a0b\r\n pm.max_spare_servers #\uff0c\u4fdd\u8bc1\u7a7a\u95f2\u8fdb\u7a0b\u6570\u6700\u5927\u503c\uff0c\u5982\u679c\u7a7a\u95f2\u8fdb\u7a0b\u5927\u4e8e\u6b64\u503c\uff0c\u6b64\u8fdb\u884c\u6e05\u7406\r\n...\r\n<\/pre>\npm\uff1a\u8868\u793a\u4f7f\u7528\u90a3\u79cd\u65b9\u5f0f\uff0c\u6709\u4e24\u4e2a\u503c\u53ef\u4ee5\u9009\u62e9\uff0c\u5c31\u662fstatic\uff08\u9759\u6001\uff09\u6216\u8005dynamic\uff08\u52a8\u6001\uff09\u3002<\/p>\n
\u5728\u66f4\u8001\u4e00\u4e9b\u7684\u7248\u672c\u4e2d\uff0cdynamic\u88ab\u79f0\u4f5capache-like\u3002\u8fd9\u4e2a\u8981\u6ce8\u610f\u770b\u914d\u7f6e\u6587\u4ef6\u7684\u8bf4\u660e\u3002<\/p>\n
\u4e0b\u97624\u4e2a\u53c2\u6570\u7684\u610f\u601d\u5206\u522b\u4e3a\uff1a<\/p>\n
\r\npm.max_children\uff1a\u9759\u6001\u65b9\u5f0f\u4e0b\u5f00\u542f\u7684php-fpm\u8fdb\u7a0b\u6570\u91cf\r\npm.start_servers\uff1a\u52a8\u6001\u65b9\u5f0f\u4e0b\u7684\u8d77\u59cbphp-fpm\u8fdb\u7a0b\u6570\u91cf\r\npm.min_spare_servers\uff1a\u52a8\u6001\u65b9\u5f0f\u4e0b\u7684\u6700\u5c0fphp-fpm\u8fdb\u7a0b\u6570\r\npm.max_spare_servers\uff1a\u52a8\u6001\u65b9\u5f0f\u4e0b\u7684\u6700\u5927php-fpm\u8fdb\u7a0b\u6570\u91cf\r\n<\/pre>\n\u533a\u522b<\/strong><\/span><\/div>\n\u5982\u679cdm\u8bbe\u7f6e\u4e3a static\uff0c\u90a3\u4e48\u5176\u5b9e\u53ea\u6709pm.max_children\u8fd9\u4e2a\u53c2\u6570\u751f\u6548\u3002\u7cfb\u7edf\u4f1a\u5f00\u542f\u8bbe\u7f6e\u6570\u91cf\u7684php-fpm\u8fdb\u7a0b\u3002<\/p>\n
\u5982\u679cdm\u8bbe\u7f6e\u4e3a dynamic\uff0c\u90a3\u4e48pm.max_children\u53c2\u6570\u5931\u6548\uff0c\u540e\u97623\u4e2a\u53c2\u6570\u751f\u6548\u3002<\/p>\n
\u7cfb\u7edf\u4f1a\u5728php-fpm\u8fd0\u884c\u5f00\u59cb \u7684\u65f6\u5019\u542f\u52a8pm.start_servers\u4e2aphp-fpm\u8fdb\u7a0b\uff0c\u7136\u540e\u6839\u636e\u7cfb\u7edf\u7684\u9700\u6c42\u52a8\u6001\u5728pm.min_spare_servers\u548cpm.max_spare_servers\u4e4b\u95f4\u8c03\u6574php-fpm\u8fdb\u7a0b\u6570<\/p>\n
\u5173\u4e8e\u6570\u91cf\u7684\u8ba1\u7b97\u65b9\u6cd5\u53ef\u4ee5\u901a\u8fc7memory_get_peak_usage(true)\u8fd9\u4e2a\u51fd\u6570\u83b7\u5f97\u5185\u5b58\u5cf0\u503c\uff0c\u4ee5\u6b64\u4f5c\u4e3a\u5355\u4e2a\u8bf7\u6c42\u7684\u7a0b\u5e8f\u5185\u5b58\u6d88\u8017\u6d88\u8017\u91cf\uff0c\u5e76\u8003\u8651\u8fdbphp-fpm\u672c\u8eab\u7684\u57fa\u7840\u5185\u5b58\u6d88\u8017\uff0c\u53ef\u4ee5\u5f97\u5230\u4e00\u4e2a\u8fd1\u4f3c\u7684\u5355\u8fdb\u7a0b\u5185\u5b58\u6d88\u8017\u91cf\u3002<\/p>\n
\n\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/wuxiaobai.win\/archives\/221<\/a><\/p>\n