{"id":31481,"date":"2026-06-25T10:00:00","date_gmt":"2026-06-25T02:00:00","guid":{"rendered":"https:\/\/cn.hostease.com\/blog\/uncategorized\/wordpress-502-php-fpm-database\/"},"modified":"2026-06-25T10:00:00","modified_gmt":"2026-06-25T02:00:00","slug":"wordpress-502-php-fpm-database","status":"publish","type":"post","link":"https:\/\/cn.hostease.com\/blog\/tutorials\/wordpress-502-php-fpm-database\/","title":{"rendered":"WordPress 502 \u9519\u8bef\u6392\u67e5\u8def\u5f84\uff1a\u4ece PHP-FPM \u5230\u6570\u636e\u5e93\u8fde\u63a5\u9010\u5c42\u5b9a\u4f4d"},"content":{"rendered":"<p><img decoding=\"async\" alt=\"WordPress 502 \u6392\u67e5\u5c01\u9762\u56fe\" src=\"https:\/\/cn.hostease.com\/blog\/wp-content\/uploads\/2026\/07\/wordpress-502-php-fpm-database-cover.webp\" \/><\/p>\n<p>\u4f60\u7684 WordPress \u7f51\u7ad9\u7a81\u7136\u5f39\u51fa&#8221;502 Bad Gateway&#8221;\uff0c\u5982\u4f55\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\uff1f502 \u9519\u8bef\u610f\u5473\u7740 Nginx \u6216 Apache \u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\uff0c\u6ca1\u80fd\u4ece\u540e\u7aef\u62ff\u5230\u6709\u6548\u54cd\u5e94\uff0c\u95ee\u9898\u53ef\u80fd\u51fa\u5728 PHP \u89e3\u6790\u5c42\u3001\u6570\u636e\u5e93\u5c42\uff0c\u751a\u81f3\u64cd\u4f5c\u7cfb\u7edf\u8d44\u6e90\u672c\u8eab\u3002\u8fd9\u7bc7\u6587\u7ae0\u5c06\u6559\u4f60\u4e00\u5957\u4ece\u5916\u5230\u5185\u3001\u9010\u5c42\u5b9a\u4f4d\u7684\u6392\u67e5\u8def\u5f84\uff0c\u5e2e\u4f60\u5feb\u901f\u627e\u5230 WordPress 502 \u7684\u6839\u56e0\u5e76\u7ed9\u51fa\u53ef\u6267\u884c\u7684\u4fee\u590d\u65b9\u6848\u3002<\/p>\n<h2>\u5148\u641e\u6e05\u695a 502 \u5230\u5e95\u662f\u8c01\u62a5\u7684<\/h2>\n<p>\u5728\u52a8\u624b\u6392\u67e5\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u7406\u89e3 502 \u9519\u8bef\u7684\u4ea7\u751f\u673a\u5236\u3002\u5178\u578b\u7684 WordPress\uff08\u4e00\u79cd\u5f00\u6e90\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf\uff09\u6258\u7ba1\u67b6\u6784\u662f\u8fd9\u6837\u7684\uff1a\u7528\u6237\u8bf7\u6c42\u5148\u5230\u8fbe Web \u670d\u52a1\u5668\uff08Nginx \u6216 Apache\uff09\uff0cWeb \u670d\u52a1\u5668\u518d\u628a PHP \u8bf7\u6c42\u8f6c\u53d1\u7ed9 PHP-FPM\uff08FastCGI \u8fdb\u7a0b\u7ba1\u7406\u5668\uff0c\u8d1f\u8d23\u89e3\u6790 PHP \u4ee3\u7801\u7684\u72ec\u7acb\u670d\u52a1\uff09\uff0cPHP-FPM \u6267\u884c\u5b8c\u540e\u628a\u7ed3\u679c\u8fd4\u56de\u7ed9 Web \u670d\u52a1\u5668\u3002\u5982\u679c PHP-FPM \u6ca1\u6709\u5728\u89c4\u5b9a\u65f6\u95f4\u5185\u54cd\u5e94\uff0c\u6216\u8005\u76f4\u63a5\u62d2\u7edd\u4e86\u8fde\u63a5\uff0cWeb \u670d\u52a1\u5668\u5c31\u4f1a\u5411\u7528\u6237\u8fd4\u56de 502\u3002<\/p>\n<p>\u6240\u4ee5 502 \u672c\u8d28\u4e0a\u662f\u4e00\u4e2a&#8221;\u4e0a\u6e38\u65e0\u54cd\u5e94&#8221;\u7684\u4fe1\u53f7\uff0c\u800c\u4e0d\u662f WordPress \u672c\u8eab\u7684\u7a0b\u5e8f\u9519\u8bef\u3002\u660e\u786e\u4e86\u8fd9\u4e00\u70b9\uff0c\u6392\u67e5\u65b9\u5411\u5c31\u5f88\u6e05\u6670\u4e86\uff1a\u8981\u4e48\u662f PHP-FPM \u8fdb\u7a0b\u51fa\u4e86\u95ee\u9898\uff0c\u8981\u4e48\u662f\u6570\u636e\u5e93\u8fde\u63a5\u963b\u585e\u5bfc\u81f4 PHP \u811a\u672c\u5361\u6b7b\uff0c\u8981\u4e48\u662f\u670d\u52a1\u5668\uff08\u4e91\u670d\u52a1\u5668\uff08\u4e00\u79cd\u6309\u9700\u5206\u914d\u8ba1\u7b97\u8d44\u6e90\u7684\u865a\u62df\u5316\u4e3b\u673a\uff09\u6216 VPS\uff08\u865a\u62df\u4e13\u7528\u670d\u52a1\u5668\uff09\uff09\u8d44\u6e90\u8017\u5c3d\u3002<\/p>\n<h2>\u7b2c\u4e00\u5c42\u6392\u67e5\uff1aPHP-FPM \u8fdb\u7a0b\u72b6\u6001<\/h2>\n<p>PHP-FPM \u662f\u6700\u5bb9\u6613\u51fa\u95ee\u9898\u7684\u4e00\u5c42\u3002\u5f53\u5e76\u53d1\u8bf7\u6c42\u8d85\u8fc7\u8fdb\u7a0b\u6c60\u4e0a\u9650\u65f6\uff0c\u65b0\u8bf7\u6c42\u4f1a\u6392\u961f\u7b49\u5f85\uff0c\u5982\u679c\u7b49\u5f85\u65f6\u95f4\u8d85\u8fc7\u4e86 Nginx \u7684 <code>fastcgi_read_timeout<\/code>\uff0c\u5c31\u4f1a\u89e6\u53d1 502\u3002<\/p>\n<p><strong>\u68c0\u67e5 PHP-FPM \u662f\u5426\u5728\u8fd0\u884c\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">systemctl status php8.2-fpm\n<\/code><\/pre>\n<p>\u5982\u679c\u670d\u52a1\u5df2\u7ecf\u6302\u6389\uff0c\u5148\u7528 <code>systemctl restart php8.2-fpm<\/code> \u6062\u590d\uff0c\u7136\u540e\u68c0\u67e5\u65e5\u5fd7\u627e\u539f\u56e0\uff1a<\/p>\n<pre><code class=\"language-bash\">tail -50 \/var\/log\/php8.2-fpm.log\n<\/code><\/pre>\n<p>\u65e5\u5fd7\u91cc\u5982\u679c\u9891\u7e41\u51fa\u73b0 <code>server reached max_children<\/code>\uff0c\u8bf4\u660e\u8fdb\u7a0b\u6c60\u592a\u5c0f\u4e86\u3002\u6253\u5f00 PHP-FPM \u914d\u7f6e\u6587\u4ef6\uff08\u901a\u5e38\u5728 <code>\/etc\/php\/8.2\/fpm\/pool.d\/www.conf<\/code>\uff09\uff0c\u627e\u5230\u8fd9\u51e0\u884c\uff1a<\/p>\n<pre><code class=\"language-ini\">pm = dynamic\npm.max_children = 50\npm.start_servers = 5\npm.min_spare_servers = 5\npm.max_spare_servers = 35\npm.max_requests = 500\n<\/code><\/pre>\n<p><code>pm.max_children<\/code> \u51b3\u5b9a\u540c\u65f6\u80fd\u5904\u7406\u591a\u5c11\u4e2a PHP \u8bf7\u6c42\u3002\u8ba1\u7b97\u65b9\u5f0f\u5f88\u7b80\u5355\uff1a\u7528\u670d\u52a1\u5668\u53ef\u7528\u5185\u5b58\u9664\u4ee5\u5355\u4e2a PHP \u8fdb\u7a0b\u7684\u5e73\u5747\u5185\u5b58\u5360\u7528\u3002\u4e00\u4e2a\u5178\u578b\u7684 WordPress \u7ad9\u70b9\uff0c\u6bcf\u4e2a PHP \u8fdb\u7a0b\u5927\u7ea6\u5360\u7528 40-80MB \u5185\u5b58\u3002\u5982\u679c\u4f60\u7684 VPS \u6709 4GB \u5185\u5b58\uff0c\u7cfb\u7edf\u548c\u5176\u4ed6\u670d\u52a1\u5360 1GB\uff0c\u5269\u4e0b GB \u9664\u4ee5 60MB\uff0c\u5927\u7ea6\u80fd\u5f00 50 \u4e2a\u5b50\u8fdb\u7a0b\u3002<\/p>\n<p>\u53e6\u4e00\u4e2a\u5173\u952e\u53c2\u6570\u662f <code>pm.max_requests<\/code>\uff0c\u5b83\u63a7\u5236\u6bcf\u4e2a\u5b50\u8fdb\u7a0b\u5904\u7406\u591a\u5c11\u6b21\u8bf7\u6c42\u540e\u81ea\u52a8\u91cd\u542f\u3002\u8bbe\u4e3a 0 \u8868\u793a\u6c38\u4e0d\u91cd\u542f\uff0c\u8fd9\u53ef\u80fd\u5bfc\u81f4\u5185\u5b58\u6cc4\u6f0f\u7d2f\u79ef\u3002\u5efa\u8bae\u8bbe\u4e3a 500-1000\uff0c\u8ba9\u8fdb\u7a0b\u5b9a\u671f\u56de\u6536\u3002<\/p>\n<p><strong>\u5feb\u901f\u9a8c\u8bc1 PHP-FPM \u662f\u5426\u6062\u590d\u6b63\u5e38\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\"># \u67e5\u770b\u5f53\u524d\u6d3b\u8dc3\u8fdb\u7a0b\u6570\nps aux | grep php-fpm | grep -v grep | wc -l\n\n# \u67e5\u770b FPM \u8fdb\u7a0b\u6c60\u72b6\u6001\uff08\u9700\u8981\u914d\u7f6e pm.status_path\uff09\ncurl http:\/\/127.0.0.1\/status\n<\/code><\/pre>\n<p><img decoding=\"async\" alt=\"PHP-FPM \u8fdb\u7a0b\u6392\u67e5\u6d41\u7a0b\u56fe\" src=\"https:\/\/cn.hostease.com\/blog\/wp-content\/uploads\/2026\/07\/wordpress-502-php-fpm-database-php-fpm.webp\" \/><\/p>\n<h2>\u7b2c\u4e8c\u5c42\u6392\u67e5\uff1a\u6570\u636e\u5e93\u8fde\u63a5\u4e0e\u6162\u67e5\u8be2<\/h2>\n<p>\u5982\u679c PHP-FPM \u8fdb\u7a0b\u6570\u6b63\u5e38\u4f46 502 \u4f9d\u7136\u51fa\u73b0\uff0c\u4e0b\u4e00\u6b65\u5e94\u8be5\u6000\u7591\u6570\u636e\u5e93\u3002WordPress \u7684\u6bcf\u4e2a\u9875\u9762\u8bf7\u6c42\u51e0\u4e4e\u90fd\u4f1a\u89e6\u53d1\u591a\u6b21\u6570\u636e\u5e93\u67e5\u8be2\uff0c\u5982\u679c MySQL\uff08\u4e00\u79cd\u5e7f\u6cdb\u4f7f\u7528\u7684\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff09\u54cd\u5e94\u53d8\u6162\uff0cPHP \u811a\u672c\u5c31\u4f1a\u88ab\u963b\u585e\uff0c\u6700\u7ec8\u88ab Nginx \u5224\u5b9a\u4e3a\u8d85\u65f6\u3002<\/p>\n<p><strong>\u68c0\u67e5 MySQL \u662f\u5426\u6709\u8fde\u63a5\u5806\u79ef\uff1a<\/strong><\/p>\n<pre><code class=\"language-sql\">SHOW PROCESSLIST;\n<\/code><\/pre>\n<p>\u5982\u679c\u770b\u5230\u5927\u91cf\u72b6\u6001\u4e3a <code>Waiting for table metadata lock<\/code> \u6216 <code>Sending data<\/code> \u7684\u67e5\u8be2\uff0c\u8bf4\u660e\u5b58\u5728\u9501\u8868\u6216\u6162\u67e5\u8be2\u3002\u7ee7\u7eed\u67e5\u770b\u6162\u67e5\u8be2\u65e5\u5fd7\uff1a<\/p>\n<pre><code class=\"language-bash\"># \u5148\u786e\u8ba4\u6162\u67e5\u8be2\u65e5\u5fd7\u662f\u5426\u5f00\u542f\nSHOW VARIABLES LIKE 'slow_query_log';\nSHOW VARIABLES LIKE 'long_query_time';\n\n# \u5f00\u542f\u6162\u67e5\u8be2\u65e5\u5fd7\uff08\u4e34\u65f6\uff09\nSET GLOBAL slow_query_log = 'ON';\nSET GLOBAL long_query_time = 2;\n<\/code><\/pre>\n<p>WordPress \u5e38\u89c1\u7684\u6162\u67e5\u8be2\u573a\u666f\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><code>wp_options<\/code> \u8868\u7684 <code>autoload<\/code> \u5b57\u6bb5\u52a0\u8f7d\u4e86\u8fc7\u591a\u65e0\u7528\u6570\u636e<\/li>\n<li><code>wp_postmeta<\/code> \u8868\u7f3a\u5c11\u7d22\u5f15\uff0c\u5bfc\u81f4 <code>JOIN<\/code> \u67e5\u8be2\u5168\u8868\u626b\u63cf<\/li>\n<li>\u67d0\u4e9b\u63d2\u4ef6\u9891\u7e41\u5199\u5165 <code>wp_options<\/code> \u7684 <code>cron<\/code> \u76f8\u5173\u884c\uff0c\u9020\u6210\u884c\u9501\u7ade\u4e89<\/li>\n<\/ul>\n<p><strong>\u4f18\u5316 wp_options \u7684 autoload\uff1a<\/strong><\/p>\n<pre><code class=\"language-sql\">-- \u67e5\u770b autoload \u4e86\u591a\u5c11\u6570\u636e\nSELECT SUM(LENGTH(option_value)) as total_bytes\nFROM wp_options\nWHERE autoload = 'yes';\n\n-- \u627e\u51fa\u6700\u5927\u7684 autoload \u9879\nSELECT option_name, LENGTH(option_value) as size\nFROM wp_options\nWHERE autoload = 'yes'\nORDER BY size DESC\nLIMIT 20;\n<\/code><\/pre>\n<p>\u5982\u679c autoload \u6570\u636e\u8d85\u8fc7 1MB\uff0c\u5c31\u5e94\u8be5\u6e05\u7406\u4e0d\u518d\u9700\u8981\u7684\u63d2\u4ef6\u6b8b\u7559\u6570\u636e\u3002\u5bf9\u4e8e\u786e\u5b9a\u4e0d\u9700\u8981\u81ea\u52a8\u52a0\u8f7d\u7684\u9009\u9879\uff0c\u6267\u884c\uff1a<\/p>\n<pre><code class=\"language-sql\">UPDATE wp_options SET autoload = 'no' WHERE option_name = 'some_old_plugin_option';\n<\/code><\/pre>\n<p><strong>\u68c0\u67e5\u6700\u5927\u8fde\u63a5\u6570\uff1a<\/strong><\/p>\n<pre><code class=\"language-sql\">SHOW VARIABLES LIKE 'max_connections';\nSHOW STATUS LIKE 'Threads_connected';\n<\/code><\/pre>\n<p>\u5982\u679c <code>Threads_connected<\/code> \u7ecf\u5e38\u63a5\u8fd1 <code>max_connections<\/code>\uff0c\u8bf4\u660e\u8fde\u63a5\u6c60\u5feb\u6ee1\u4e86\u3002MySQL \u9ed8\u8ba4 151 \u4e2a\u8fde\u63a5\uff0c\u5bf9\u4e8e\u4e2d\u5c0f\u578b WordPress \u7ad9\u70b9\u901a\u5e38\u591f\u7528\uff0c\u4f46\u5982\u679c\u540c\u4e00\u53f0\u670d\u52a1\u5668\u8dd1\u4e86\u591a\u4e2a\u7ad9\u70b9\uff0c\u5c31\u9700\u8981\u9002\u5f53\u8c03\u9ad8\u6216\u8005\u8003\u8651\u628a\u6570\u636e\u5e93\u72ec\u7acb\u90e8\u7f72\u3002\u66f4\u591a WordPress \u6027\u80fd\u4f18\u5316\u601d\u8def\u53ef\u4ee5\u53c2\u8003 <a href=\"https:\/\/cn.hostease.com\/blog\/wordpress\/\">WordPress \u5efa\u7ad9\u4f18\u5316\u6307\u5357<\/a>\uff0c\u5176\u4e2d\u6709\u4e0d\u5c11\u9488\u5bf9\u6570\u636e\u5e93\u5c42\u9762\u7684\u5b9e\u6218\u7ecf\u9a8c\u3002<\/p>\n<h2>\u7b2c\u4e09\u5c42\u6392\u67e5\uff1aNginx \u914d\u7f6e\u4e0e\u8d85\u65f6\u53c2\u6570<\/h2>\n<p>\u6709\u65f6\u5019 PHP-FPM \u548c\u6570\u636e\u5e93\u90fd\u6ca1\u95ee\u9898\uff0c\u95ee\u9898\u51fa\u5728 Nginx \u81ea\u8eab\u7684\u8d85\u65f6\u8bbe\u7f6e\u4e0a\u3002\u5982\u679c WordPress \u9875\u9762\u9700\u8981\u6267\u884c\u8f83\u957f\u65f6\u95f4\u7684\u64cd\u4f5c\uff08\u6bd4\u5982\u6279\u91cf\u5bfc\u5165\u3001\u751f\u6210\u5927\u91cf\u7f29\u7565\u56fe\uff09\uff0c\u800c Nginx \u7684\u8d85\u65f6\u9608\u503c\u8bbe\u5f97\u592a\u77ed\uff0c\u4e5f\u4f1a\u62a5 502\u3002<\/p>\n<p><strong>\u68c0\u67e5 Nginx \u7684 fastcgi \u8d85\u65f6\u914d\u7f6e\uff1a<\/strong><\/p>\n<pre><code class=\"language-nginx\">location ~ \\.php$ {\n    fastcgi_pass unix:\/run\/php\/php8.2-fpm.sock;\n    fastcgi_read_timeout 300;\n    fastcgi_send_timeout 300;\n    fastcgi_connect_timeout 300;\n    include fastcgi_params;\n}\n<\/code><\/pre>\n<p>\u9ed8\u8ba4\u7684 <code>fastcgi_read_timeout<\/code> \u662f 60 \u79d2\uff0c\u5bf9\u4e8e\u666e\u901a\u9875\u9762\u8bf7\u6c42\u8db3\u591f\u4e86\u3002\u4f46\u5982\u679c\u4f60\u7684 WordPress \u540e\u53f0\u64cd\u4f5c\u7ecf\u5e38\u8d85\u65f6\uff0c\u53ef\u4ee5\u628a\u5b83\u63d0\u9ad8\u5230 300 \u79d2\u3002\u6ce8\u610f\uff1a\u8fd9\u4e2a\u503c\u4e0d\u5e94\u8be5\u8bbe\u5f97\u592a\u9ad8\uff0c\u5426\u5219\u771f\u6b63\u7684\u5361\u6b7b\u8bf7\u6c42\u4f1a\u957f\u65f6\u95f4\u5360\u7528 Nginx \u8fde\u63a5\u3002<\/p>\n<p><strong>\u68c0\u67e5 Nginx \u9519\u8bef\u65e5\u5fd7\u786e\u8ba4 502 \u539f\u56e0\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">tail -100 \/var\/log\/nginx\/error.log | grep &quot;502&quot;\n<\/code><\/pre>\n<p>\u5e38\u89c1\u7684\u65e5\u5fd7\u4fe1\u606f\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><code>connect() failed (111: Connection refused)<\/code> \u2192 PHP-FPM \u6ca1\u6709\u5728\u76d1\u542c<\/li>\n<li><code>upstream timed out (110: Connection timed out)<\/code> \u2192 PHP-FPM \u5904\u7406\u592a\u6162<\/li>\n<li><code>recv() failed (104: Connection reset by peer)<\/code> \u2192 PHP-FPM \u8fdb\u7a0b\u5d29\u6e83<\/li>\n<\/ul>\n<p>\u6bcf\u79cd\u9519\u8bef\u5bf9\u5e94\u4e0d\u540c\u7684\u4fee\u590d\u65b9\u5411\uff0c\u65e5\u5fd7\u91cc\u7684\u5177\u4f53\u4fe1\u606f\u6bd4\u76f2\u76ee\u8c03\u6574\u914d\u7f6e\u8981\u9ad8\u6548\u5f97\u591a\u3002<\/p>\n<h2>\u5b9e\u6218\u6392\u67e5\u6e05\u5355\uff1a\u9047\u5230 502 \u65f6\u7684 5 \u6b65\u5feb\u901f\u8bca\u65ad<\/h2>\n<p>\u628a\u4e0a\u9762\u7684\u6392\u67e5\u903b\u8f91\u6574\u7406\u6210\u4e00\u4e2a\u53ef\u76f4\u63a5\u6267\u884c\u7684\u6e05\u5355\uff0c\u4e0b\u6b21\u9047\u5230 502 \u65f6\u6309\u987a\u5e8f\u8d70\u4e00\u904d\uff1a<\/p>\n<ol>\n<li><strong>\u786e\u8ba4 PHP-FPM \u72b6\u6001<\/strong>\uff1a<code>systemctl status php8.2-fpm<\/code>\uff0c\u770b\u8fdb\u7a0b\u662f\u5426\u5b58\u6d3b\u3001\u65e5\u5fd7\u662f\u5426\u6709 <code>max_children<\/code> \u8b66\u544a<\/li>\n<li><strong>\u68c0\u67e5\u670d\u52a1\u5668\u8d44\u6e90<\/strong>\uff1a<code>free -h<\/code> \u770b\u5185\u5b58\u662f\u5426\u8017\u5c3d\uff0c<code>top<\/code> \u770b CPU \u8d1f\u8f7d\uff0c<code>df -h<\/code> \u770b\u78c1\u76d8\u662f\u5426\u6ee1<\/li>\n<li><strong>\u68c0\u67e5\u6570\u636e\u5e93\u8fde\u63a5<\/strong>\uff1a<code>mysqladmin processlist<\/code> \u770b\u662f\u5426\u6709\u5927\u91cf\u6162\u67e5\u8be2\u6216\u9501\u8868<\/li>\n<li><strong>\u68c0\u67e5 Nginx \u9519\u8bef\u65e5\u5fd7<\/strong>\uff1a<code>tail \/var\/log\/nginx\/error.log<\/code> \u627e\u5230\u5177\u4f53\u7684 502 \u539f\u56e0<\/li>\n<li><strong>\u68c0\u67e5\u6587\u4ef6\u63cf\u8ff0\u7b26<\/strong>\uff1a<code>ulimit -n<\/code> \u770b\u7cfb\u7edf\u9650\u5236\uff0c\u9ad8\u5e76\u53d1\u4e0b\u53ef\u80fd\u9700\u8981\u8c03\u9ad8 <code>\/etc\/security\/limits.conf<\/code> \u4e2d\u7684 <code>nofile<\/code><\/li>\n<\/ol>\n<p>\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662f\u6258\u7ba1\u578b WordPress \u4e3b\u673a\uff0c\u8fd9\u4e9b\u5e95\u5c42\u914d\u7f6e\u901a\u5e38\u5df2\u7ecf\u7531\u8fd0\u7ef4\u56e2\u961f\u9884\u4f18\u5316\u8fc7\uff0c\u9047\u5230 502 \u7684\u6982\u7387\u4f1a\u4f4e\u5f88\u591a\u3002\u4f46\u5bf9\u4e8e\u81ea\u5df1\u7ba1\u7406\u670d\u52a1\u5668\u7684\u7ad9\u957f\u6765\u8bf4\uff0c\u638c\u63e1\u8fd9\u5957\u6392\u67e5\u8def\u5f84\u662f\u5fc5\u5907\u6280\u80fd\u3002<\/p>\n<p><img decoding=\"async\" alt=\"502 \u6392\u67e5\u51b3\u7b56\u6d41\u7a0b\u56fe\" src=\"https:\/\/cn.hostease.com\/blog\/wp-content\/uploads\/2026\/07\/wordpress-502-php-fpm-database-decision-flow.webp\" \/><\/p>\n<h2>\u9884\u9632 502 \u7684\u957f\u671f\u4f18\u5316\u5efa\u8bae<\/h2>\n<p>\u6392\u67e5\u548c\u4fee\u590d\u53ea\u662f\u6cbb\u6807\uff0c\u8981\u4ece\u6839\u672c\u4e0a\u51cf\u5c11 502 \u7684\u51fa\u73b0\u9891\u7387\uff0c\u5efa\u8bae\u4ece <a href=\"https:\/\/cn.hostease.com\/blog\/optimization\/\">\u7f51\u7ad9\u4f18\u5316\u4e0e\u6027\u80fd\u8c03\u4f18<\/a> \u7684\u89d2\u5ea6\u6301\u7eed\u6539\u8fdb\uff1a<\/p>\n<p><strong>\u542f\u7528 OPcache \u51cf\u5c11 PHP-FPM \u8d1f\u8f7d\u3002<\/strong> OPcache \u662f PHP \u5185\u7f6e\u7684\u5b57\u8282\u7801\u7f13\u5b58\uff0c\u542f\u7528\u540e PHP \u811a\u672c\u4e0d\u9700\u8981\u6bcf\u6b21\u8bf7\u6c42\u90fd\u91cd\u65b0\u7f16\u8bd1\u3002\u5728 <code>php.ini<\/code> \u4e2d\u786e\u8ba4\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"language-ini\">opcache.enable=1\nopcache.memory_consumption=128\nopcache.max_accelerated_files=10000\nopcache.revalidate_freq=60\n<\/code><\/pre>\n<p>\u5b9e\u6d4b\u6570\u636e\u663e\u793a\uff0c\u542f\u7528 OPcache \u540e PHP \u6267\u884c\u65f6\u95f4\u5e73\u5747\u7f29\u77ed 50-70%\uff0c\u8fd9\u610f\u5473\u7740 PHP-FPM \u8fdb\u7a0b\u80fd\u66f4\u5feb\u91ca\u653e\uff0c\u540c\u6837\u7684 <code>pm.max_children<\/code> \u80fd\u625b\u4f4f\u66f4\u9ad8\u7684\u5e76\u53d1\u3002<\/p>\n<p><strong>\u914d\u7f6e WordPress \u5bf9\u8c61\u7f13\u5b58\u3002<\/strong> \u5b89\u88c5 Redis \u6216 Memcached\uff0c\u914d\u5408 <code>Redis Object Cache<\/code> \u63d2\u4ef6\uff0c\u628a\u9891\u7e41\u67e5\u8be2\u7684\u6570\u636e\u5e93\u7ed3\u679c\u7f13\u5b58\u5230\u5185\u5b58\u4e2d\u3002\u8fd9\u80fd\u76f4\u63a5\u51cf\u5c11 MySQL \u7684\u67e5\u8be2\u538b\u529b\uff0c\u4ece\u6e90\u5934\u964d\u4f4e\u6570\u636e\u5e93\u5bfc\u81f4 502 \u7684\u6982\u7387\u3002<\/p>\n<p><strong>\u5b9a\u671f\u6e05\u7406 WordPress \u5783\u573e\u6570\u636e\u3002<\/strong> \u4f7f\u7528 <code>WP-Optimize<\/code> \u63d2\u4ef6\u5b9a\u671f\u6e05\u7406\u6587\u7ae0\u4fee\u8ba2\u7248\u672c\u3001\u5783\u573e\u8bc4\u8bba\u3001\u8fc7\u671f\u7684\u4e34\u65f6\u6570\u636e\u3002\u4e00\u4e2a\u8fd0\u884c\u4e86\u4e24\u5e74\u7684 WordPress \u7ad9\u70b9\uff0c<code>wp_posts<\/code> \u8868\u4e2d\u7684\u4fee\u8ba2\u7248\u672c\u53ef\u80fd\u5360\u5230\u603b\u884c\u6570\u7684 60% \u4ee5\u4e0a\uff0c\u8fd9\u4e9b\u6570\u636e\u62d6\u6162\u4e86\u67e5\u8be2\u901f\u5ea6\u5374\u6ca1\u6709\u4efb\u4f55\u7528\u5904\u3002<\/p>\n<p><strong>\u76d1\u63a7\u5e76\u8bbe\u7f6e\u544a\u8b66\u3002<\/strong> \u90e8\u7f72\u7b80\u5355\u7684\u76d1\u63a7\u811a\u672c\uff0c\u5728 PHP-FPM \u8fdb\u7a0b\u6570\u8d85\u8fc7\u9608\u503c\u6216 MySQL \u8fde\u63a5\u6570\u63a5\u8fd1\u4e0a\u9650\u65f6\u53d1\u9001\u544a\u8b66\u3002\u63a8\u8350\u4f7f\u7528 <a href=\"https:\/\/cn.hostease.com\/dedicated-server\/\">Hostease \u72ec\u7acb\u670d\u52a1\u5668<\/a> \u65b9\u6848\u642d\u914d Zabbix \u6216 Prometheus\uff0c\u5b9e\u73b0 7\u00d724 \u5c0f\u65f6\u7684\u81ea\u52a8\u5316\u76d1\u63a7\uff0c\u628a\u95ee\u9898\u6d88\u706d\u5728\u7528\u6237\u611f\u77e5\u4e4b\u524d\u3002<\/p>\n<p>\u603b\u7ed3\u6765\u8bf4\uff0cWordPress 502 \u9519\u8bef\u7684\u6392\u67e5\u6838\u5fc3\u601d\u8def\u662f&#8221;\u5148\u786e\u8ba4\u54ea\u4e00\u5c42\u51fa\u4e86\u95ee\u9898\uff0c\u518d\u9488\u5bf9\u90a3\u4e00\u5c42\u6df1\u5165\u6392\u67e5&#8221;\u3002PHP-FPM \u8fdb\u7a0b\u4e0d\u8db3\u3001\u6570\u636e\u5e93\u6162\u67e5\u8be2\u3001Nginx \u8d85\u65f6\u914d\u7f6e\uff0c\u8fd9\u4e09\u4e2a\u662f\u6700\u5e38\u89c1\u7684\u539f\u56e0\u3002\u628a\u8fd9\u7bc7\u6587\u7ae0\u91cc\u7684\u6392\u67e5\u6e05\u5355\u6536\u85cf\u597d\uff0c\u4e0b\u6b21\u9047\u5230 502 \u65f6\u5c31\u80fd\u5feb\u901f\u5b9a\u4f4d\u5e76\u89e3\u51b3\u95ee\u9898\u3002\u5982\u679c\u4f60\u6b63\u5728\u5bfb\u627e\u4e00\u53f0\u9884\u914d\u7f6e\u597d PHP-FPM \u548c MySQL \u4f18\u5316\u53c2\u6570\u7684\u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u8003\u8651\u770b\u770b <a href=\"https:\/\/cn.hostease.com\/vps\/\">Hostease \u7684 VPS \u65b9\u6848<\/a>\uff0c\u7701\u53bb\u81ea\u5df1\u6298\u817e\u5e95\u5c42\u914d\u7f6e\u7684\u65f6\u95f4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6559\u4f60\u4ece PHP-FPM \u8fdb\u7a0b\u3001\u6570\u636e\u5e93\u8fde\u63a5\u3001Nginx \u914d\u7f6e\u4e09\u4e2a\u5c42\u9762\u6392\u67e5 WordPress \u9891\u7e41 502 \u9519\u8bef\uff0c\u9644\u5e26\u5177\u4f53\u547d\u4ee4\u548c\u914d\u7f6e\u793a\u4f8b\u3002<\/p>\n","protected":false},"author":2,"featured_media":31478,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4099],"tags":[4495,4496,84,682,3734],"class_list":["post-31481","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-4495","tag-php-fpm-2","tag-wordpress","tag-682","tag-3734"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/cn.hostease.com\/blog\/wp-content\/uploads\/2026\/07\/wordpress-502-php-fpm-database-cover.webp","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/posts\/31481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/comments?post=31481"}],"version-history":[{"count":0,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/posts\/31481\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/media\/31478"}],"wp:attachment":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/media?parent=31481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/categories?post=31481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/tags?post=31481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}