{"id":89,"date":"2016-05-23T10:08:38","date_gmt":"2016-05-23T02:08:38","guid":{"rendered":"http:\/\/120.27.50.22\/wordpress\/?p=89"},"modified":"2016-05-23T10:08:38","modified_gmt":"2016-05-23T02:08:38","slug":"nginx%e6%8f%90%e7%a4%ba%ef%bc%9a500-internal-server-error%e9%94%99%e8%af%af%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.homconnect.cn\/?p=89","title":{"rendered":"nginx\u63d0\u793a\uff1a500 Internal Server Error\u9519\u8bef\u7684\u89e3\u51b3\u65b9\u6cd5"},"content":{"rendered":"<p>\u73b0\u5728\u8d8a\u6765\u8d8a\u591a\u7684\u7ad9\u70b9\u5f00\u59cb\u7528 Nginx ,(&#8220;engine x&#8221;) \u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684 HTTP \u548c\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u4e5f\u662f\u4e00\u4e2a IMAP\/POP3\/SMTP \u4ee3\u7406\u670d\u52a1\u5668\u3002 Nginx \u662f\u7531 Igor Sysoev \u4e3a\u4fc4\u7f57\u65af\u8bbf\u95ee\u91cf\u7b2c\u4e8c\u7684 Rambler.ru \u7ad9\u70b9\u5f00\u53d1\u7684\uff0c\u5b83\u5df2\u7ecf\u5728\u8be5\u7ad9\u70b9\u8fd0\u884c\u8d85\u8fc7\u4e24\u5e74\u534a\u4e86\u3002Igor \u5c06\u6e90\u4ee3\u7801\u4ee5\u7c7bBSD\u8bb8\u53ef\u8bc1\u7684\u5f62\u5f0f\u53d1\u5e03\u3002<\/p>\n<p>\u5728\u9ad8\u5e76\u53d1\u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\uff0cNginx\u662fApache\u670d\u52a1\u5668\u4e0d\u9519\u7684\u66ff\u4ee3\u54c1\u3002Nginx\u540c\u65f6\u4e5f\u53ef\u4ee5\u4f5c\u4e3a7\u5c42\u8d1f\u8f7d\u5747\u8861\u670d\u52a1\u5668\u6765\u4f7f\u7528\u3002\u6839\u636e\u6d4b\u8bd5\u7ed3\u679c\uff0cNginx 0.6.31 + PHP 5.2.6 (FastCGI) \u53ef\u4ee5\u627f\u53d73\u4e07\u4ee5\u4e0a\u7684\u5e76\u53d1\u8fde\u63a5\u6570\uff0c\u76f8\u5f53\u4e8e\u540c\u7b49\u73af\u5883\u4e0bApache\u768410\u500d\u3002<\/p>\n<p>\u4f46\u5f88\u591a\u4eba\u7528 Nginx \u7684\u65f6\u5019\u90fd\u4f1a\u51fa\u73b0 500 \u9519\u8bef\uff0c\u6839\u636e\u6211\u4f7f\u7528\u7684\u60c5\u51b5\u6765\u770b\uff0c\u5f88\u5927\u4e00\u90e8\u5206\u539f\u56e0\u662f \u56e0\u4e3a\u6587\u4ef6\u6253\u5f00\u53e5\u67c4\u592a\u5c0f\u6709\u5173\u3002<\/p>\n<p><!--more--><br \/>\n<strong>\u5728linux \u4e0b \u4f7f\u7528\u8fd9\u4e2a\u547d\u4ee4\u589e\u52a0\u8fdb\u7a0b\u6253\u5f00\u7684\u6587\u4ef6\u53e5\u67c4\u3002<\/strong><br \/>\nulimit -SHn 51200<br \/>\n\u9ed8\u8ba4\u53ea\u75281000 \u5f53\u94fe\u63a5\u6570\u5c0f\u7684\u65f6\u5019\u770b\u4e0d\u51fa\u6765\uff0c\u4f7f\u7528\u8fd9\u79cd\u5904\u7406\u65b9\u6cd5\u53ef\u4ee5\u6709\u6548\u9632\u6b62500\u9519\u8bef\u51fa\u73b0\u3002<br \/>\n\u4eca\u5929\u8bbf\u95ee\u7f51\u7ad9\u7684\u65f6\u5019,\u5076\u5c14\u4f1a\u9047\u4e0a500 Internal Server Error\u7684\u9519\u8bef\u63d0\u793a\u9875\u9762.<br \/>\n\u67e5\u4e86\u76f8\u5173\u8d44\u6599\u8ba4\u4e3a\u662f\u8bbf\u95ee\u8fc7\u5927,\u7cfb\u7edf\u5185\u6838\u8fdb\u7a0b\u53d7\u9650\u624d\u51fa\u73b0\u7684.<\/p>\n<p>\u7b54\u6848\u5982\u4e0b:<\/p>\n<p>$ ulimit -n<br \/>\n11095<\/p>\n<p>\u7a0b\u5e8f\u9650\u5236\u53ea\u80fd\u6253\u5f0011095\u4e2a\u6587\u4ef6,ulimit\u547d\u4ee4\u662f\u8bbe\u7f6e\u5f53\u524d\u7528\u6237\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u62e5\u6709\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u6570\u91cf.<br \/>\n\u770b\u6765\u662f\u6a21\u62df\u7684\u5e76\u53d1\u6570\u592a\u591a\u4e86\uff0c\u9700\u8981\u8c03\u6574\u4e00\u4e0bnginx.conf\u7684\u5e76\u53d1\u8bbe\u7f6e\u6570\uff0c\uff08\u6211\u7684\u914d\u7f6e\u4e3b\u673a\u7684\u5185\u5b582G,CPU\u4e3a2.8G,\uff09<\/p>\n<blockquote><p>vi \/etc\/nginx\/nginx.conf<br \/>\nevents {<br \/>\nworker_connections 1024;<br \/>\n}<\/p><\/blockquote>\n<p>\u8c03\u6574\u4e3a<\/p>\n<blockquote><p>events {<br \/>\nworker_connections 10240;<br \/>\n}<\/p><\/blockquote>\n<p>\u8fd8\u662f\u4f1a\u51fa\u73b0\u4e0a\u9762\u95ee\u9898\uff0c\u4f7f\u7528<br \/>\n[root@qimutian nginx]# cat \/proc\/sys\/fs\/file-max<br \/>\n8192<br \/>\n\u6587\u4ef6\u7cfb\u7edf\u6700\u5927\u53ef\u6253\u5f00\u6587\u4ef6\u6570<br \/>\n[root@qimutian nginx]# ulimit -n<br \/>\n1024<br \/>\n\u7a0b\u5e8f\u9650\u5236\u53ea\u80fd\u6253\u5f001024\u4e2a\u6587\u4ef6<br \/>\n\u4f7f\u7528[root@qimutian nginx]# ulimit -n 8192\u8c03\u6574\u4e00\u4e0b<br \/>\n\u6216\u8005\u6c38\u4e45\u8c03\u6574\u6253\u5f00\u6587\u4ef6\u6570 \u53ef\u5728\u542f\u52a8\u6587\u4ef6\/etc\/rc.d\/rc.local\u672b\u5c3e\u6dfb\u52a0\uff08\u5728\/etc\/sysctl.conf\u672b\u5c3e\u6dfb\u52a0fs.file-max=8192\uff09<br \/>\nulimit -n 8192<br \/>\n\u8c03\u6574CentOS5\u6587\u4ef6\u6253\u5f00\u6570<br \/>\n\u4f7f\u7528ulimit -a\u4e00\u4e0b\uff0c\u53d1\u73b0OPEN FILES\u4e0d\u80fd\u9ed8\u8ba4\u8d85\u8fc71024\uff0c\u6628\u5929\u7684\u5728\u8fdb\u884c\u538b\u529b\u6d4b\u8bd5\u65f6\uff0c\u51fa\u73b0500\u9519\u8bef\uff0c\u5177\u4f53\u8bf7\u67e5\u770b<br \/>\nnginx\u51fa\u73b0 500 Internal Server Error<br \/>\n\u65e9\u4e0a\u8d77\u6765\u770b\u4e00\u4e0b\uff0c\u53d1\u73b0\u539f\u6765\u662f\u901a\u8fc7\u5982\u4e0b\u65b9\u5f0f\u8c03\u6574<br \/>\n\u65b9\u6cd51 \uff08\u6c38\u4e45\u8c03\u6574\uff09<\/p>\n<p>vi \/etc\/security\/limits.conf<\/p>\n<p>\u5728\u6587\u4ef6\u672b\u52a0\u4e0a\uff1a<\/p>\n<p>* soft nofile 8192<br \/>\n* hard nofile 20480<\/p>\n<p>\u540c\u65f6vi \/etc\/sysctl.conf\u672b\u5c3e\u6dfb\u52a0<br \/>\nfs.file-max=8192<br \/>\n\u91cd\u65b0\u542f\u52a8\uff0c\u5728\u4f7f\u7528ulimit -n\u67e5\u770b\u7684\u6570\u5df2\u7ecf\u662f8192<\/p>\n<p>\u65b9\u6cd52 \uff08\u4e34\u65f6\u7528\uff09<\/p>\n<p>\u76f4\u63a5\u5728\u7ec8\u7aef\u8f93\u5165 ulimit -n 8192 \u6309\u56de\u8f66\u5c31ok\u4e86<\/p>\n<p><strong>500 Internal Server Error\u9519\u8bef\u8865\u5145\uff1a<br \/>\n<\/strong><br \/>\n1\u3001\u786c\u76d8\u7a7a\u95f4\u6ee1\u4e86<\/p>\n<p>\u4f7f\u7528 df -k \u67e5\u770b\u786c\u76d8\u7a7a\u95f4\u662f\u5426\u6ee1\u4e86\u3002\u6e05\u7406\u786c\u76d8\u7a7a\u95f4\u5c31\u53ef\u4ee5\u89e3\u51b3500\u9519\u8bef\u3002nginx\u5982\u679c\u5f00\u542f\u4e86access log\uff0c\u5728\u4e0d\u9700\u8981\u7684\u60c5\u51b5\u4e0b\uff0c\u6700\u597d\u5173\u95edaccess log\u3002access log\u4f1a\u5360\u7528\u5927\u91cf\u786c\u76d8\u7a7a\u95f4\u3002<\/p>\n<p>2\u3001nginx\u914d\u7f6e\u6587\u4ef6\u9519\u8bef<\/p>\n<p>\u8fd9\u91cc\u4e0d\u662f\u6307\u8bed\u6cd5\u9519\u8bef\uff0cnginx\u5982\u679c\u914d\u7f6e\u6587\u4ef6\u6709\u8bed\u6cd5\u9519\u8bef\uff0c\u542f\u52a8\u7684\u65f6\u5019\u5c31\u4f1a\u63d0\u793a\u3002\u5f53\u914d\u7f6erewrite\u7684\u65f6\u5019\uff0c\u6709\u4e9b\u89c4\u5219\u5904\u7406\u4e0d\u5f53\u4f1a\u51fa\u73b0500\u9519\u8bef\uff0c\u8bf7\u4ed4\u7ec6\u68c0\u67e5\u81ea\u5df1\u7684rewrite\u89c4\u5219\u3002\u5982\u679c\u914d\u7f6e\u6587\u4ef6\u91cc\u6709\u4e9b\u53d8\u91cf\u8bbe\u7f6e\u4e0d\u5f53\uff0c\u4e5f\u4f1a\u51fa\u73b0500\u9519\u8bef\uff0c\u6bd4\u5982\u5f15\u7528\u4e86\u4e00\u4e2a\u6ca1\u6709\u503c\u7684\u53d8\u91cf\u3002<\/p>\n<p>3\u3001\u5982\u679c\u4e0a\u9762\u7684\u95ee\u9898\u90fd\u4e0d\u5b58\u5728\u53ef\u80fd\u662f\u6a21\u62df\u7684\u5e76\u53d1\u6570\u592a\u591a\u4e86\uff0c\u9700\u8981\u8c03\u6574\u4e00\u4e0bnginx.conf\u7684\u5e76\u53d1\u8bbe\u7f6e\u6570<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\u662f\uff1a<\/p>\n<p>1 \u6253\u5f00\/etc\/security\/limits.conf\u6587\u4ef6\uff0c\u52a0\u4e0a\u4e24\u53e5<\/p>\n<blockquote><p>* soft nofile 65535<br \/>\n* hard nofile 65535<\/p><\/blockquote>\n<p>2 \u6253\u5f00\/etc\/nginx\/nginx.conf<br \/>\n\u5728worker_processes\u7684\u4e0b\u9762\u589e\u52a0\u4e00\u884c<\/p>\n<blockquote><p>worker_rlimit_nofile 65535;<\/p><\/blockquote>\n<p>3 \u91cd\u65b0\u542f\u52a8nginx\uff0c\u91cd\u65b0\u8f7d\u5165\u8bbe\u7f6e<\/p>\n<blockquote><p>kill -9 `ps -ef | grep php | grep -v grep | awk &#8216;{print $2}&#8217;`<br \/>\n\/usr\/bin\/spawn-fcgi -a 127.0.0.1 -p 9000 -C 100 -u www-data -f \/usr\/bin\/php-cgi<br \/>\nkillall -HUP nginx<\/p><\/blockquote>\n<p>\u91cd\u542f\u540e\u518d\u770bnginx\u7684\u9519\u8bef\u65e5\u5fd7\uff0c\u4e5f\u6ca1\u6709\u53d1\u73b0500\u62a5\u9519\u7684\u60c5\u51b5\u4e86\u3002<\/p>\n<p>4\u3001\u6709\u53ef\u80fd\u662f\u6570\u636e\u5e93\u95ee\u9898\u6211\u7684\u5728nginx\u65e5\u5fd7php\u65e5\u5fd7\u90fd\u6ca1\u6709\u53d1\u73b0\u4ec0\u4e48\u95ee\u9898, \u6700\u540e\u53d1\u73b0\u6570\u636e\u5e93\u8bbf\u95ee\u4e0d\u4e86,\u4fee\u6b63\u540e\u95ee\u9898\u89e3\u51b3.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73b0\u5728\u8d8a\u6765\u8d8a\u591a\u7684\u7ad9\u70b9\u5f00\u59cb\u7528 Nginx ,(&#8220;engine x&#8221;) \u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684 HT &hellip; <a href=\"http:\/\/www.homconnect.cn\/?p=89\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cnginx\u63d0\u793a\uff1a500 Internal Server Error\u9519\u8bef\u7684\u89e3\u51b3\u65b9\u6cd5\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[45],"tags":[47,46],"_links":{"self":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts\/89"}],"collection":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=89"}],"version-history":[{"count":1,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":90,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions\/90"}],"wp:attachment":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}