{"id":1157,"date":"2012-07-15T00:41:56","date_gmt":"2012-07-14T16:41:56","guid":{"rendered":"https:\/\/blog.rexdf.org\/?p=1157"},"modified":"2012-07-15T00:41:56","modified_gmt":"2012-07-14T16:41:56","slug":"nginx%e5%92%8clighttpd%e5%af%b9%e6%af%94","status":"publish","type":"post","link":"https:\/\/blog.rexdf.org\/ja\/2012\/07\/nginx%e5%92%8clighttpd%e5%af%b9%e6%af%94\/","title":{"rendered":"Nginx\u548clighttpd\u5bf9\u6bd4"},"content":{"rendered":"<h1><strong><span style=\"color: #ff0000;\">\u80cc\u666f<\/span><\/strong><\/h1>\n<p>lighttpd\u548cnginx\u662f\u8fd1\u5e74\u6765\u4e24\u4e2a\u6d41\u884c\u7684\u9ad8\u6027\u80fdweb server\u3002nginx\u5728\u8fd1\u51e0\u5e74\u5192\u8d77\u5f88\u5feb\uff0c\u6839\u636enetcraft\u5bf92010\u5e742\u6708\u6240\u6709\u7f51\u7ad9\u57df\u540d\u7684web server\u5e02\u573a\u4efd\u989d\u8c03\u67e5\u663e\u793a\uff0cnginx\u5360\u636e\u7b2c4\u4f4d\uff0c\u5df2\u660e\u663e\u8d85\u8d8a\u4e86lighttpd\uff0c\u5982\u4e0b\u56fe\u793a\uff1a<\/p>\n<p>\u767e\u5ea6\u6709\u4e00\u4e9b\u670d\u52a1\u4f7f\u7528lighttpd\uff0c\u6211\u4eec\u5e0c\u671b\u5bf9 nginx\u5f00\u5c55\u8c03\u7814\uff0c\u5e76\u548clighttpd\u8fdb\u884c\u5bf9\u6bd4\u3002<\/p>\n<h1><strong><span style=\"color: #ff0000;\">\u6982\u8ff0<\/span><\/strong><\/h1>\n<p>Nginx\u548clighttpd\u57fa\u672c\u4e0a\u662f\u540c\u8d28\u7684\uff0c\u90fd\u662f\u91c7\u7528\u57fa\u4e8eepoll\/kqueue\/select\u7684\u5168\u5f02\u6b65\u4e8b\u4ef6\u6a21\u578b\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u7ef4\u6301\u5927\u91cf\u7684\u8fde\u63a5\uff0c\u4e0d\u60e7\u6015\u6162\u8fde\u63a5\u653b\u51fb\u3002\u4e24\u8005\u90fd\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684HTTP\u670d\u52a1\u529f\u80fd\uff0c\u4f8b\u5982\u538b\u7f29\u3001url rewrite\u3001\u865a\u62df\u4e3b\u673a\u3001SSL\u3001proxy\u7b49\u7b49\u3002<br \/>\nNginx\u5927\u91cf\u6a21\u4eff\u4e86apache\u7684\u8bbe\u8ba1\u98ce\u683c\uff0c\u6bd4\u5982\u6a21\u5757\u7684\u5b9a\u4e49\u3001\u88c5\u914d\u3001\u4ee5\u53ca\u914d\u7f6e\u6570\u636e\u7684\u89e3\u6790\u548c\u7ec4\u7ec7\u65b9\u5f0f\u7b49\u7b49\u3002Lighttpd\u5219\u662f\u81ea\u5df1\u8bbe\u8ba1\u7684\u4e00\u5957\u3002 \u548clighttpd\u76f8\u6bd4\uff0cNginx\u505a\u4e8b\u66f4\u52a0\u7cbe\u7ec6\uff0c\u5b83\u63d0\u4f9b\u7684\u4e00\u4e9b\u6bd4\u8f83\u7279\u522b\u3002<br \/>\nNginx\u7684\u4ee3\u7801\u5165\u624b\u66f4\u56f0\u96be\u4e00\u4e9b\uff08\u4e3b\u89c2\u770b\u6cd5\uff09\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0cNginx\u5185\u90e8\u7684HTTP\u72b6\u6001\u8fc1\u79fb\u662f\u6bd4\u8f83\u9690\u6027\u7684\uff0c\u5b83\u901a\u8fc7\u4e00\u7cfb\u5217\u7684handler\u8d4b\u503c\u6765\u5b9e\u73b0\uff0c\u5982\u679c\u8981\u5b8c\u6574\u5730\u8ffd\u8e2a\u4e00\u6b21HTTP\u8bf7\u6c42\u7684\u5904\u7406\u8fc7\u7a0b\uff0c\u6bd4\u8f83\u8d39\u52b2\u3002\u8fd9\u4e2a\u5c31\u8bf4\u660e\uff0c\u4e00\u65e6\u51fa\u4e86\u95ee\u9898\uff0c\u8ffd\u67e5\u6bd4\u8f83\u56f0\u96be\u3002\u800clighttpd\u7684\u4ee3\u7801\u4e2d\u6709\u4e00\u4e2a\u663e\u5f0f\u7684HTTP\u72b6\u6001\u8fc1\u79fb\uff0c\u4e00\u76ee\u4e86\u7136\uff0c\u76f8\u6bd4\u4e4b\u4e0b\u6bd4\u8f83\u597d\u770b\u4e00\u4e9b\u3002<br \/>\n\u6269\u5c55\u6a21\u5757\u5f00\u53d1\u65b9\u9762\uff0cnginx\u7684module\u6a21\u4eff\u4e86apache\u7684\u8bbe\u8ba1\u548c\u5b9e\u73b0\u65b9\u5f0f\uff0c\u548clighttpd\u662f\u5b8c\u5168\u4e0d\u540c\u7684\u3002\u4e3b\u89c2\u611f\u89c9\u4e0anginx\u6a21\u5757\u5f00\u53d1\u7684\u5165\u95e8\u95e8\u69db\u66f4\u9ad8\u4e00\u4e9b\uff0c\u56e0\u4e3a\u5fc5\u987b\u5f04\u6e05\u695anginx\u7684\u5185\u90e8\u8fd0\u884c\u673a\u5236\u624d\u597d\u786e\u8ba4\u4f60\u5199\u7684\u4ee3\u7801\u5230\u5e95\u6709\u6ca1\u6709\u95ee\u9898\u548c\u9690\u60a3\u3002<br \/>\n\u548clighttpd\u4e00\u6837\uff0cnginx\u540c\u6837\u5b58\u5728\u7740\u5f00\u53d1\u6587\u6863\u5f88\u5c11\u7684\u95ee\u9898\u3002\u6700\u597d\u7684\u6587\u6863\u8fd8\u662f\u6e90\u7801\u672c\u8eab\u3002<\/p>\n<h1><strong><span style=\"color: #ff0000;\">\u529f\u80fd<\/span><\/strong><\/h1>\n<p>Nginx\u5b8c\u5168\u4e0d\u652f\u6301\u52a8\u6001\u5e93so\uff0c\u6240\u4ee5\u5b83\u7684\u6a21\u5757\u90fd\u5fc5\u987b\u9759\u6001\u7f16\u8bd1\uff0c\u4e14\u4e0d\u80fd\u52a8\u6001\u52a0\u8f7d\u3002\u8981\u52a0\u8f7d\u54ea\u4e9b\u6a21\u5757\uff0c\u6a21\u5757\u6309\u7167\u600e\u6837\u7684\u987a\u5e8f\u6267\u884c\uff0c\u90fd\u662f\u5728\u7f16\u8bd1\u671f\u7531 configure\u6307\u5b9a\u7684\uff0c\u5982\u679c\u8981\u8c03\u6574\uff0c\u4e5f\u53ea\u80fd\u91cd\u65b0\u7f16\u8bd1\u4e00\u904d\uff0c\u65e0\u6cd5\u901a\u8fc7\u6539\u914d\u7f6e\u6765\u5b9e\u73b0\u3002\u5728\u8fd9\u65b9\u9762\uff0cLighttpd\u505a\u5f97\u6bd4nginx\u597d\u3002Lighttpd\u652f \u6301\u52a8\u6001so\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u8c03\u6574\u5404\u6a21\u5757\u7684\u5148\u540e\u987a\u5e8f\uff0c\u5728\u67d0\u4e9b\u5e94\u7528\u573a\u666f\u4e0b\uff0c\u8c03\u6574\u6a21\u5757\u7684\u5148\u540e\u987a\u5e8f\u662f\u5f88\u6709\u7528\u7684\u3002<br \/>\n\u6761\u4ef6\u914d\u7f6e\u8bed\u6cd5\u7684\u7075\u6d3b\u6027\uff0clighttpd\u6bd4nginx\u8981\u597d\u4e00\u4e9b\u3002Lighttpd\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u914d\u7f6e\u6210\u8fd9\u6837\uff1a<br \/>\n$HTTP[\u201curl\u201d] =~ \u201c\u2026\u201d {<br \/>\nProxy-core.backends = (\u201c10.1.1.1:8080\u201d, \u201c10.1.1.2:8080\u201d, \u2026)<br \/>\nProxy-core.balancer = \u201cround-robin\u201d<br \/>\nProxy-core.protocol = \u201chttp\u201d<br \/>\n\u2026\u2026<br \/>\n}<\/p>\n<p>$HTTP[\u201chost\u201d] =~ \u201c\u2026\u201d {<br \/>\nAccess.deny-all = \u201cenable\u201d<br \/>\n}<\/p>\n<p>$HTTP[\u201cuseragent\u201d] =~ \u201c\u2026\u201d {<br \/>\nurl.redirect = (\u201c\u201d =&gt; \u201chttp:\/\/example.com\/\u201d)<br \/>\nurl.redirect-code = 302<br \/>\n}<\/p>\n<p>$HTTP[\u201curl\u201d] =~ \u201c\u2026\u201d {<br \/>\n$HTTP[\u201cquerystring\u201d] =~ \u201c\u2026\u201d {<br \/>\n$HTTP[\u201creferer\u201d] =~ \u201c\u2026\u201d {<br \/>\n\u2026<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n\u5728nginx\u4e2d\uff0c\u5982\u679c\u6a21\u5757\u672c\u8eab\u6ca1\u63d0\u4f9b\u6761\u4ef6\u652f\u6301\u7684\u8bdd\uff0c\u9700\u8981\u4f9d\u8d56rewrite\u6a21\u5757\u505a\u4e00\u6b21\u5185\u90e8\u8df3\u8f6c\uff0c\u628a\u53d8\u5316\u53cd\u6620\u5230url\u4e0a\uff0c\u518d\u901a\u8fc7location\u4f7f\u5176\u751f\u6548\u3002<br \/>\n\u5728\u4e00\u4e9b\u5177\u4f53\u7684\u529f\u80fd\u70b9\u4e0a\uff0cnginx\u548clighttpd\u5404\u6709\u7279\u70b9\uff1a<br \/>\n\u6709\u4e00\u4e9b\u6bd4\u8f83\u7ec6\u8282\u7684\u5730\u65b9\uff0cnginx\u8003\u8651\u5f97\u6bd4lighttpd\u5468\u5168\uff0c\u6bd4\u5982nginx\u53ef\u4ee5\u914d\u7f6eHTTP\u5934\u90e8\u7684\u957f\u5ea6\u3001HTTP\u8bf7\u6c42\u7684\u8bfb\u5199\u8d85\u65f6 \u7b49\uff0clighttpd\u7684\u5b98\u65b9\u7248\u672c\u662f\u4e0d\u652f\u6301\u7684\uff0c\u767e\u5ea6\u5bf9\u6b64\u8fdb\u884c\u4e86\u6539\u826f\u3002\u518d\u4f8b\u5982nginx\u53ef\u4ee5\u914d\u7f6elisten\u961f\u5217\u957f\u5ea6\u3001nginx\u8fdb\u7a0b\u8d77\u6765\u540e \u6302\u5728\u54ea\u4e2aCPU\u6838\u4e0a\u8fd0\u884c\uff0clighttpd\u73b0\u5728\u8fd8\u4e0d\u652f\u6301\u3002<br \/>\nNginx\u7684proxy\u529f\u80fd\u6bd4lighttpd\u5f3a\u5927\uff0c\u4e3b\u8981\u662fproxy cache\uff0c\u53e6\u5916\u8fd8\u6709\u4e00\u4e9b\u7ec6\u8282\u4e0a\u7684\u5904\u7406\u3002\u6bd4\u5982nginx\u652f\u63014xx\/5xx\u9519\u8bef\u81ea\u52a8\u91cd\u8bd5\u4e0b\u4e00\u4e2a\u540e\u7aef\u3002\u4f46\u662fLighttpd\u7684proxy\u73b0\u5728\u8fd8\u652f\u6301scgi \u548cajp\u4e24\u79cd\u540e\u7aef\u8f6c\u53d1\u534f\u8bae\uff0cnginx\u4e0d\u652f\u6301\u3002<br \/>\nNginx\u6709\u4e00\u4e9b\u6bd4\u8f83\u6709\u7279\u8272\u7684\u529f\u80fdmodule\uff0c\u4f8b\u5982\uff1a<br \/>\n1\uff09secure_link\uff0c\u53ef\u4ee5\u7528\u6765\u9632\u76d7\u94fe\uff0c\u76ee\u524d\u5728CDN\u4e0a\u6709\u5e94\u7528\u3002\u8fd9\u4e2a\u529f\u80fd\u5f88\u4e0d\u9519\uff0c\u53ef\u4ee5\u8003\u8651\u5728lighttpd\u4e0a\u5f00\u53d1\u76f8\u5e94\u7684\u6a21\u5757\u3002<br \/>\n2\uff09geoip\uff0c\u7528\u6237\u7ed9\u914d\u7f6e\u4e00\u4e2aip\u5730\u7406\u4fe1\u606f\u6570\u636e\u6587\u4ef6\uff0cnginx\u53ef\u4ee5\u4ee5\u6b64\u4e3a\u6839\u636e\uff0c\u5224\u65ad\u5ba2\u6237\u7aefip\u6765\u81ea\u54ea\u4e2a\u56fd\u5bb6\u548c\u57ce\u5e02\u3002<\/p>\n<h1><strong><span style=\"color: #ff0000;\">\u6027\u80fd<\/span><\/strong><\/h1>\n<p>\u6839\u636e\u7b80\u5355\u6027\u80fd\u5bf9\u6bd4\uff0cNginx\u7684\u6027\u80fd\u6bd4lighttpd\u7565\u597d\u3002\u539f\u56e0\u53ef\u80fd\u6709\u4ee5\u4e0b\u51e0\u65b9\u9762\uff1a<br \/>\n1. Lighttpd\u542f\u52a8\u4e86\u51e0\u4e2a\u8f85\u52a9\u7ebf\u7a0b\uff0c\u6709\u52a0\u9501\u7ade\u4e89\u884c\u4e3a\uff0c\u8fd9\u6837\u4f1a\u4f7f\u6027\u80fd\u6709\u6240\u964d\u4f4e\uff08\u7ebf\u7a0b\u4e2a\u6570\u662f\u53ef\u914d\u7684\uff0c\u8fd9\u91cc\u8fd8\u6709\u4f18\u5316\u7684\u4f59\u5730\uff09\uff1bnginx\u5b8c\u5168\u4e0d\u6d89\u53ca\u7ebf\u7a0b\uff0c\u4e0d\u52a0\u9501\u3002<br \/>\n2. Lighttpd\u6709\u52a8\u6001so\uff0cnginx\u5168\u9759\u6001\u7f16\u8bd1\uff0c\u52a8\u6001\u5e93\u6267\u884c\u6548\u7387\u6bd4\u9759\u6001\u6162\u5927\u7ea65%~10%\u5de6\u53f3\u3002<br \/>\n3. Nginx\u5728\u7ec6\u8282\u4f18\u5316\u4e0a\u53ef\u80fd\u505a\u5f97\u66f4\u597d\u4e00\u4e9b\u3002\u4f8b\u5982nginx\u7684epoll\u662fET\uff08\u8fb9\u7f18\u89e6\u53d1\uff09\u7684\uff0c\u800clighttpd\u7684epoll\u662fLT\uff08\u6c34\u5e73\u89e6\u53d1\uff09\u7684\u3002<br \/>\nnginx\u7684\u6027\u80fd\u8981\u597d\u4e00\u4e9b\uff0c\u4e0d\u8fc7\u5bf9\u5927\u591a\u6570\u5e94\u7528\u6765\u8bf4\uff0clighttpd\u7684\u6027\u80fd\u6307\u6807\u5df2\u591f\u7528\u4e86\uff0c\u4e00\u4e2a\u7cfb\u7edf\u4e3b\u8981\u7684\u74f6\u9888\u5f80\u5f80\u662f\u5728\u540e\u7aef\u3002\u7531\u4e8elighttpd\u5177\u6709\u52a8\u6001\u6a21\u5757\u7684\u52a0\u8f7d\u80fd\u529b\uff0c\u9002\u5408\u975e\u5e38\u9700\u8981\u7075\u6d3b\u914d\u7f6e\u7684\u573a\u5408\u3002<br \/>\n\u603b\u4f53\u800c\u8a00\uff0cnginx\u548clighttpd\u90fd\u662f\u975e\u5e38\u597d\u7684web server\u9009\u62e9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f lighttpd\u548cnginx\u662f\u8fd1\u5e74\u6765\u4e24\u4e2a\u6d41\u884c\u7684\u9ad8\u6027\u80fdweb server\u3002 &hellip; <a href=\"https:\/\/blog.rexdf.org\/ja\/2012\/07\/nginx%e5%92%8clighttpd%e5%af%b9%e6%af%94\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[19],"tags":[100,101],"class_list":["post-1157","post","type-post","status-publish","format-standard","hentry","category-site-build","tag-lighttpd","tag-nginx"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/posts\/1157","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/comments?post=1157"}],"version-history":[{"count":0,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/posts\/1157\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/media?parent=1157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/categories?post=1157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/tags?post=1157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}