{"id":50955,"date":"2024-10-08T14:58:19","date_gmt":"2024-10-08T06:58:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/50955\/"},"modified":"2024-10-08T14:58:20","modified_gmt":"2024-10-08T06:58:20","slug":"nginx-%e6%96%b0%e6%89%8b%e6%95%99%e7%a8%8b%ef%bc%9a%e8%a8%ad%e7%bd%ae%e5%b7%a5%e4%bd%9c%e9%80%a3%e6%8e%a5","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/50955\/","title":{"rendered":"Nginx \u65b0\u624b\u6559\u7a0b\uff1a\u8a2d\u7f6e\u5de5\u4f5c\u9023\u63a5"},"content":{"rendered":"<h1 id=\"nginx-%e6%96%b0%e6%89%8b%e6%95%99%e7%a8%8b%ef%bc%9a%e8%a8%ad%e7%bd%ae%e5%b7%a5%e4%bd%9c%e9%80%a3%e6%8e%a5-NASTFXKKwn\">Nginx \u65b0\u624b\u6559\u7a0b\uff1a\u8a2d\u7f6e\u5de5\u4f5c\u9023\u63a5<\/h1>\n<p>Nginx \u662f\u4e00\u6b3e\u9ad8\u6548\u80fd\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u975c\u614b\u5167\u5bb9\u7684\u63d0\u4f9b\u3001\u53cd\u5411\u4ee3\u7406\u3001\u8ca0\u8f09\u5747\u8861\u7b49\u5834\u666f\u3002\u5c0d\u65bc\u65b0\u624b\u4f86\u8aaa\uff0c\u4e86\u89e3\u5982\u4f55\u8a2d\u7f6e Nginx \u7684\u5de5\u4f5c\u9023\u63a5\u662f\u975e\u5e38\u91cd\u8981\u7684\uff0c\u56e0\u70ba\u9019\u76f4\u63a5\u5f71\u97ff\u5230\u4f3a\u670d\u5668\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u8a2d\u7f6e Nginx \u7684\u5de5\u4f5c\u9023\u63a5\uff0c\u5e6b\u52a9\u60a8\u66f4\u597d\u5730\u7ba1\u7406\u60a8\u7684\u4f3a\u670d\u5668\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e5%b7%a5%e4%bd%9c%e9%80%a3%e6%8e%a5%ef%bc%9f-NASTFXKKwn\">\u4ec0\u9ebc\u662f\u5de5\u4f5c\u9023\u63a5\uff1f<\/h2>\n<p>\u5728 Nginx \u4e2d\uff0c\u5de5\u4f5c\u9023\u63a5\u662f\u6307\u4f3a\u670d\u5668\u540c\u6642\u80fd\u5920\u8655\u7406\u7684\u9023\u63a5\u6578\u91cf\u3002\u9019\u4e9b\u9023\u63a5\u5305\u62ec\u5ba2\u6236\u7aef\u7684\u8acb\u6c42\u3001\u4f3a\u670d\u5668\u7684\u97ff\u61c9\u4ee5\u53ca\u5176\u4ed6\u5167\u90e8\u64cd\u4f5c\u3002\u5408\u7406\u8a2d\u7f6e\u5de5\u4f5c\u9023\u63a5\u7684\u6578\u91cf\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4f3a\u670d\u5668\u7684\u8655\u7406\u80fd\u529b\uff0c\u6e1b\u5c11\u5ef6\u9072\uff0c\u5f9e\u800c\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<h2 id=\"nginx-%e7%9a%84%e5%9f%ba%e6%9c%ac%e9%85%8d%e7%bd%ae-NASTFXKKwn\">Nginx \u7684\u57fa\u672c\u914d\u7f6e<\/h2>\n<p>\u5728\u958b\u59cb\u8a2d\u7f6e\u5de5\u4f5c\u9023\u63a5\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u5df2\u7d93\u5b89\u88dd\u4e86 Nginx\u3002\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u901a\u904e\u7de8\u8f2f Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u4f86\u9032\u884c\u8a2d\u7f6e\u3002\u901a\u5e38\uff0cNginx \u7684\u914d\u7f6e\u6587\u4ef6\u4f4d\u65bc \/etc\/nginx\/nginx.conf\u3002<\/p>\n<h3 id=\"%e7%b7%a8%e8%bc%af%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6-NASTFXKKwn\">\u7de8\u8f2f\u914d\u7f6e\u6587\u4ef6<\/h3>\n<pre><code>sudo nano \/etc\/nginx\/nginx.conf<\/code><\/pre>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u60a8\u53ef\u4ee5\u627e\u5230\u4ee5\u4e0b\u5e7e\u500b\u91cd\u8981\u7684\u6307\u4ee4\uff1a<\/p>\n<ul>\n<li><code>worker_processes<\/code>\uff1a\u5b9a\u7fa9\u5de5\u4f5c\u9032\u7a0b\u7684\u6578\u91cf\u3002<\/li>\n<li><code>worker_connections<\/code>\uff1a\u5b9a\u7fa9\u6bcf\u500b\u5de5\u4f5c\u9032\u7a0b\u53ef\u4ee5\u8655\u7406\u7684\u6700\u5927\u9023\u63a5\u6578\u3002<\/li>\n<\/ul>\n<h2 id=\"%e8%a8%ad%e7%bd%ae%e5%b7%a5%e4%bd%9c%e9%80%b2%e7%a8%8b%e5%92%8c%e5%b7%a5%e4%bd%9c%e9%80%a3%e6%8e%a5-NASTFXKKwn\">\u8a2d\u7f6e\u5de5\u4f5c\u9032\u7a0b\u548c\u5de5\u4f5c\u9023\u63a5<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684\u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n<pre><code>worker_processes auto;\nevents {\n    worker_connections 1024;\n}\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c<code>worker_processes auto;<\/code> \u6703\u81ea\u52d5\u6839\u64da CPU \u7684\u6838\u5fc3\u6578\u91cf\u4f86\u8a2d\u7f6e\u5de5\u4f5c\u9032\u7a0b\u7684\u6578\u91cf\uff0c\u800c <code>worker_connections 1024;<\/code> \u5247\u8a2d\u7f6e\u6bcf\u500b\u5de5\u4f5c\u9032\u7a0b\u53ef\u4ee5\u8655\u7406\u7684\u6700\u5927\u9023\u63a5\u6578\u70ba 1024\u3002<\/p>\n<h3 id=\"%e8%a8%88%e7%ae%97%e6%9c%80%e5%a4%a7%e9%80%a3%e6%8e%a5%e6%95%b8-NASTFXKKwn\">\u8a08\u7b97\u6700\u5927\u9023\u63a5\u6578<\/h3>\n<p>\u8981\u8a08\u7b97 Nginx \u7684\u6700\u5927\u9023\u63a5\u6578\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u516c\u5f0f\uff1a<\/p>\n<pre><code>\u6700\u5927\u9023\u63a5\u6578 = worker_processes * worker_connections<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u7684\u4f3a\u670d\u5668\u6709 4 \u9846 CPU \u6838\u5fc3\uff0c\u4e26\u4e14\u6bcf\u500b\u5de5\u4f5c\u9032\u7a0b\u7684\u9023\u63a5\u6578\u8a2d\u7f6e\u70ba 1024\uff0c\u90a3\u9ebc\u6700\u5927\u9023\u63a5\u6578\u5c07\u662f\uff1a<\/p>\n<pre><code>4 * 1024 = 4096<\/code><\/pre>\n<h2 id=\"%e6%b8%ac%e8%a9%a6%e9%85%8d%e7%bd%ae-NASTFXKKwn\">\u6e2c\u8a66\u914d\u7f6e<\/h2>\n<p>\u5728\u5b8c\u6210\u914d\u7f6e\u5f8c\uff0c\u60a8\u9700\u8981\u6e2c\u8a66 Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u662f\u5426\u6b63\u78ba\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u6e2c\u8a66\uff1a<\/p>\n<pre><code>sudo nginx -t<\/code><\/pre>\n<p>\u5982\u679c\u914d\u7f6e\u6b63\u78ba\uff0c\u60a8\u5c07\u770b\u5230\u985e\u4f3c\u65bc\u4ee5\u4e0b\u7684\u6d88\u606f\uff1a<\/p>\n<pre><code>nginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/code><\/pre>\n<h2 id=\"%e9%87%8d%e6%96%b0%e5%95%9f%e5%8b%95-nginx-NASTFXKKwn\">\u91cd\u65b0\u555f\u52d5 Nginx<\/h2>\n<p>\u6700\u5f8c\uff0c\u60a8\u9700\u8981\u91cd\u65b0\u555f\u52d5 Nginx \u4ee5\u4f7f\u66f4\u6539\u751f\u6548\uff1a<\/p>\n<pre><code>sudo systemctl restart nginx<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-NASTFXKKwn\">\u7e3d\u7d50<\/h2>\n<p>\u8a2d\u7f6e Nginx \u7684\u5de5\u4f5c\u9023\u63a5\u662f\u63d0\u5347\u4f3a\u670d\u5668\u6027\u80fd\u7684\u91cd\u8981\u6b65\u9a5f\u3002\u901a\u904e\u5408\u7406\u914d\u7f6e <code>worker_processes<\/code> \u548c <code>worker_connections<\/code>\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u4f3a\u670d\u5668\u7684\u8ca0\u8f09\uff0c\u78ba\u4fdd\u5176\u7a69\u5b9a\u904b\u884c\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u80fd\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u65b9\u6848\u4e5f\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u4e86\u89e3\u66f4\u591a\u95dc\u65bc <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 Nginx \u4e2d\u8a2d\u7f6e\u5de5\u4f5c\u9023\u63a5\uff0c\u63d0\u5347\u4f3a\u670d\u5668\u6027\u80fd\u8207\u6548\u7387\uff0c\u9069\u5408\u65b0\u624b\u7684\u8a73\u7d30\u6b65\u9a5f\u8207\u5be6\u7528\u6280\u5de7\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-50955","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/50955","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=50955"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/50955\/revisions"}],"predecessor-version":[{"id":50956,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/50955\/revisions\/50956"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=50955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=50955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=50955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}