{"id":687,"date":"2026-07-12T08:15:09","date_gmt":"2026-07-12T00:15:09","guid":{"rendered":"https:\/\/book.yuekegu.com\/index.php\/2026\/07\/12\/nginx-502-bad-gateway-%e6%8e%92%e6%9f%a5%e5%ae%9e%e6%88%98%ef%bc%9a%e4%b8%80%e4%b8%aa-tmp-%e7%9b%ae%e5%bd%95%e6%9d%83%e9%99%90%e5%bc%95%e5%8f%91%e7%9a%84%e8%a1%80%e6%a1%88\/"},"modified":"2026-07-12T08:15:09","modified_gmt":"2026-07-12T00:15:09","slug":"nginx-502-bad-gateway-%e6%8e%92%e6%9f%a5%e5%ae%9e%e6%88%98%ef%bc%9a%e4%b8%80%e4%b8%aa-tmp-%e7%9b%ae%e5%bd%95%e6%9d%83%e9%99%90%e5%bc%95%e5%8f%91%e7%9a%84%e8%a1%80%e6%a1%88","status":"publish","type":"post","link":"https:\/\/book.yuekegu.com\/index.php\/2026\/07\/12\/nginx-502-bad-gateway-%e6%8e%92%e6%9f%a5%e5%ae%9e%e6%88%98%ef%bc%9a%e4%b8%80%e4%b8%aa-tmp-%e7%9b%ae%e5%bd%95%e6%9d%83%e9%99%90%e5%bc%95%e5%8f%91%e7%9a%84%e8%a1%80%e6%a1%88\/","title":{"rendered":"Nginx 502 Bad Gateway \u6392\u67e5\u5b9e\u6218\uff1a\u4e00\u4e2a \/tmp \u76ee\u5f55\u6743\u9650\u5f15\u53d1\u7684\u8840\u6848"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">2026\u5e747\u670812\u65e5\u65e9\u4e0a\uff0c\u7a81\u7136\u53d1\u73b0 <code>todo.yuekegu.com<\/code> \u65e0\u6cd5\u8bbf\u95ee\uff0c\u6d4f\u89c8\u5668\u76f4\u63a5\u663e\u793a <strong>502 Bad Gateway<\/strong>\u3002\u4e8e\u662f\u5f00\u59cb\u4e86\u4e00\u573a\u6392\u67e5\u4e4b\u65c5\uff0c\u6700\u7ec8\u53d1\u73b0\u7f6a\u9b41\u7978\u9996\u7adf\u7136\u662f \u2014\u2014 <code>\/tmp<\/code> \u76ee\u5f55\u6743\u9650\u88ab\u6539\u4e86\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u95ee\u9898\u73b0\u8c61<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6d4f\u89c8\u5668\u8bbf\u95ee <code>https:\/\/todo.yuekegu.com<\/code> \u8fd4\u56de 502 Bad Gateway<\/li>\n<li>DNS \u89e3\u6790\u6b63\u5e38\uff0c\u57df\u540d\u6307\u5411 118.25.211.245<\/li>\n<li>SSL \u8bc1\u4e66\u6b63\u5e38\uff0cTLS \u63e1\u624b\u6210\u529f<\/li>\n<li>\u540c\u670d\u52a1\u5668\u7684 <code>https:\/\/grader.yuekegu.com<\/code> \u8bbf\u95ee\u6b63\u5e38<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u6392\u67e5\u8fc7\u7a0b<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u4e00\u6b65\uff1a\u786e\u8ba4502\u6765\u6e90<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7528 curl \u6d4b\u8bd5\uff0c\u8fd4\u56de 502\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ curl -sI https:\/\/todo.yuekegu.com\nHTTP\/2 502<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">DNS \u89e3\u6790\u6b63\u5e38\uff0c\u6307\u5411\u670d\u52a1\u5668 IP\uff0c\u8bf4\u660e\u95ee\u9898\u51fa\u5728\u670d\u52a1\u5668\u5185\u90e8\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u4e8c\u6b65\uff1a\u67e5\u770b Nginx \u9519\u8bef\u65e5\u5fd7<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\/www\/wwwlogs\/todo.yuekegu.com.error.log \u4e2d\u62a5\u5927\u91cf\u5982\u4e0b\u9519\u8bef\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>connect() to unix:\/tmp\/php-cgi-82.sock failed (13: Permission denied) \nwhile connecting to upstream<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u9519\u8bef\u7801 <strong>13<\/strong> \u5373 <code>EACCES<\/code>\uff0c\u8868\u793a Nginx worker \u8fdb\u7a0b\u6ca1\u6709\u6743\u9650\u8fde\u63a5 PHP-FPM \u7684 Unix socket\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u4e09\u6b65\uff1a\u5206\u6790\u6743\u9650\u914d\u7f6e<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Nginx \u4e0e PHP-FPM \u90fd\u4ee5 <code>www<\/code> \u7528\u6237\u8fd0\u884c\uff0c\u6309\u7406\u8bf4\u5e94\u8be5\u6ca1\u95ee\u9898\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>user www www<\/code> \uff08Nginx \u914d\u7f6e\uff09<\/li>\n<li><code>user = www; group = www<\/code> \uff08PHP-FPM \u914d\u7f6e\uff09<\/li>\n<li><code>listen.mode = 0600<\/code> \uff08PHP-FPM socket \u6743\u9650\uff0c\u4ec5\u6240\u6709\u8005\u53ef\u8bfb\u5199\uff09<\/li>\n<li>Socket \u6587\u4ef6 <code>\/tmp\/php-cgi-82.sock<\/code> \u6240\u6709\u8005\u4e3a <code>www<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u914d\u7f6e\u4e0a\u770b\u5b8c\u5168\u5408\u7406\uff0c\u4e3a\u4f55\u4f1a Permission denied\uff1f<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u56db\u6b65\uff1a\u6df1\u5165\u6d4b\u8bd5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7528 Python \u6d4b\u8bd5 socket \u8fde\u63a5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u4ee5 root \u6267\u884c \u2014 \u6210\u529f\n$ python3 -c \"import socket; s=socket.socket(...); s.connect('\/tmp\/php-cgi-82.sock')\"\nROOT CONNECTED OK\n\n# \u4ee5 www \u6267\u884c \u2014 \u5931\u8d25\uff01\n$ su -s \/bin\/sh www -c 'python3 -c \"...\"'\nPermissionError: [Errno 13] Permission denied<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u540c\u6837\u7528\u6237\u3001socket \u4e5f\u662f 0660\uff0c\u4e3a\u4f55 www \u81ea\u5df1\u8fde\u4e0d\u4e0a\uff1f<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u4e94\u6b65\uff1a\u53d1\u73b0\u6839\u56e0<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u68c0\u67e5 <code>\/tmp<\/code> \u76ee\u5f55\u6743\u9650\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ls -la \/\ndrwx------ 18 root root 94208 Jul 12 07:45 tmp<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7834\u6848\u4e86\uff01<\/strong> \u6807\u51c6\u7684 Linux <code>\/tmp<\/code> \u76ee\u5f55\u6743\u9650\u5e94\u4e3a <code>drwxrwxrwt<\/code>\uff08\u5373 1777\uff0c\u5e26 sticky bit\uff09\uff0c\u4f46\u8fd9\u91cc\u88ab\u6539\u6210\u4e86 <code>drwx------<\/code>\uff08700\uff09\uff0c\u53ea\u6709 root \u80fd\u8fdb\u5165\u8be5\u76ee\u5f55\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Nginx worker \u867d\u7136\u662f <code>www<\/code> \u7528\u6237\uff0c\u4f46\u8981\u8fde\u63a5\u5230 <code>\/tmp\/php-cgi-82.sock<\/code>\uff0c\u5fc5\u987b\u5148\u80fd\u8fdb\u5165 <code>\/tmp<\/code> \u76ee\u5f55\u3002\u76ee\u5f55\u672c\u8eab\u4e0d\u53ef\u8bbf\u95ee\uff0csocket \u6587\u4ef6\u6743\u9650\u518d\u5bf9\u4e5f\u6ca1\u7528\uff01<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5347\u7ea7 socket \u6743\u9650\u4e3a\u4f55\u65e0\u6548<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u5f00\u59cb\u5c1d\u8bd5\u5c06 <code>listen.mode<\/code> \u4ece 0600 \u6539\u4e3a 0666 \u4e5f\u6ca1\u89e3\u51b3\uff0c\u56e0\u4e3a\u95ee\u9898\u4e0d\u5728 socket \u6587\u4ef6\u672c\u8eab\uff0c\u800c\u662f <strong>\u901a\u5f80 socket \u7684\u8def<\/strong> \u88ab\u5835\u4f4f\u4e86\u3002Unix socket \u7684\u8bbf\u95ee\u53d7\u8def\u5f84\u4e0a\u6240\u6709\u76ee\u5f55\u7684\u6743\u9650\u63a7\u5236\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u89e3\u51b3\u65b9\u6848<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u590d <code>\/tmp<\/code> \u76ee\u5f55\u6743\u9650\u4e3a\u6b63\u786e\u503c\u5373\u53ef\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod 1777 \/tmp\nls -la \/ | grep tmp\n# \u8f93\u51fa: drwxrwxrwt ... tmp<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u590d\u540e\u7acb\u5373\u9a8c\u8bc1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u6d4b\u8bd5 www \u7528\u6237\u8fde\u63a5 socket\n$ su -s \/bin\/sh www -c 'python3 -c \"...\"'\nWWW CONNECTED OK after fix\n\n# \u6d4b\u8bd5\u7f51\u7ad9\n$ curl -sI https:\/\/todo.yuekegu.com\nHTTP\/2 200<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ad9\u70b9\u6062\u590d\u6b63\u5e38\uff01<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u7ecf\u9a8c\u603b\u7ed3<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Unix Socket \u6743\u9650\u6709\u4e24\u5c42<\/strong>\uff1a\u4e0d\u4ec5\u8981\u68c0\u67e5 socket \u6587\u4ef6\u672c\u8eab\u7684\u6743\u9650\uff0c\u8fd8\u8981\u68c0\u67e5\u8def\u5f84\u4e0a\u6240\u6709\u76ee\u5f55\u7684\u6743\u9650\u3002<\/li>\n<li><strong>Permission denied (13) \u2260 socket \u6587\u4ef6\u6743\u9650\u95ee\u9898<\/strong>\uff1a\u5f88\u591a\u65f6\u5019\u662f\u8def\u5f84\u76ee\u5f55\u4e0d\u53ef\u8fbe\u3002<\/li>\n<li><strong>\/tmp \u6743\u9650<\/strong>\uff1a\u6807\u51c6\u5e94\u4e3a <code>1777<\/code>\uff08drwxrwxrwt\uff09\uff0c\u5207\u52ff\u968f\u610f\u4fee\u6539\u3002<\/li>\n<li><strong>\u6392\u67e5\u5957\u8def<\/strong>\uff1aDNS \u2192 Nginx \u914d\u7f6e \u2192 \u9519\u8bef\u65e5\u5fd7 \u2192 \u540e\u7aef\u8fdb\u7a0b \u2192 \u6587\u4ef6\u6743\u9650\uff0c\u9010\u5c42\u6df1\u5165\u3002<\/li>\n<li><strong>\/tmp \u6743\u9650\u5f02\u5e38\u53ef\u80fd\u662f\u88ab\u6076\u610f\u7be1\u6539<\/strong>\uff0c\u4fee\u590d\u540e\u5efa\u8bae\u6392\u67e5\u5b89\u5168\u65e5\u5fd7\u786e\u8ba4\u662f\u5426\u6709\u5165\u4fb5\u8ff9\u8c61\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u6848\u4f8b\u770b\u4f3c\u7b80\u5355\uff0c\u4f46 \/tmp \u76ee\u5f55\u6743\u9650\u88ab\u6539\u8fd9\u79cd\u95ee\u9898\u5f88\u4e0d\u5e38\u89c1\uff0c\u5bb9\u6613\u8ba9\u4eba\u5728 socket \u6743\u9650\u4e0a\u7ed5\u5708\u5b50\u3002\u8bb0\u5f55\u4e8e\u6b64\uff0c\u4f9b\u8fd0\u7ef4\u540c\u53c2\u8003\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2026\u5e747\u670812\u65e5\u65e9\u4e0a\uff0c\u7a81\u7136\u53d1\u73b0 todo.yuekegu.com \u65e0\u6cd5\u8bbf\u95ee\uff0c\u6d4f\u89c8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-687","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts\/687","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/comments?post=687"}],"version-history":[{"count":0,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts\/687\/revisions"}],"wp:attachment":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/media?parent=687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/categories?post=687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/tags?post=687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}