{"id":3431,"date":"2021-03-12T21:35:15","date_gmt":"2021-03-12T13:35:15","guid":{"rendered":"http:\/\/blog.ywdevops.cn\/?p=3431"},"modified":"2021-03-12T21:57:41","modified_gmt":"2021-03-12T13:57:41","slug":"nginx","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2021\/03\/12\/nginx\/","title":{"rendered":"nginx\u6027\u80fd\u8c03\u4f18"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>1\u3001Nginx\u8fd0\u884c\u5de5\u4f5c\u8fdb\u7a0b\u6570\u91cf\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> worker\u8fdb\u7a0b\u7684\u6570\u91cf\u4f1a\u76f4\u63a5\u5f71\u54cd\u6027\u80fd \uff0cNginx\u8fd0\u884c\u5de5\u4f5c\u8fdb\u7a0b\u4e2a\u6570\u4e00\u822c\u8bbe\u7f6eCPU\u7684\u6838\u5fc3\u6216\u8005\u6838\u5fc3\u6570x2\u3002\u5982\u679c\u4e0d\u4e86\u89e3cpu\u7684\u6838\u6570\uff0c\u53ef\u4ee5top\u547d\u4ee4\u4e4b\u540e\u63091\u770b\u51fa\u6765\uff0c \u4e5f\u53ef\u4ee5\u67e5\u770b\/proc\/cpuinfo\u6587\u4ef6 grep ^processor \/proc\/cpuinfo | wc -l <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bcf\u4e00\u4e2aworker\u8fdb\u7a0b\u90fd\u662f\u5355\u7ebf\u7a0b\u8fdb\u7a0b\uff0c\u5b83\u4eec\u8c03\u7528\u5404\u4e2a\u6a21\u5757\u4ee5\u5b9e\u73b0\u591a\u79cd\u591a\u6837\u7684\u529f\u80fd\uff0c\u5982\u679c\u8fd9\u4e9b\u6a21\u5757\u786e\u8ba4\u4e0d\u4f1a\u51fa\u73b0\u963b\u585e\u5f0f\u8c03\u7528\uff0c\u90a3\u4e48\uff0c\u6709\u591a\u5c11\u4e2aCPU\u5185\u6838\u5c31\u914d\u7f6e\u591a\u5c11\u4e2aworker\u8fdb\u7a0b\uff0c\u5982\u679c\u6709\u53ef\u80fd\u51fa\u73b0\u963b\u585e\u5f0f\u8c03\u7528\uff0c\u5c31\u9700\u8981\u7a0d\u591a\u4e00\u4e9bworker\u8fdb\u7a0b\u3002<br>\u4f8b\u5982 \uff1a <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4e1a\u52a1\u9700\u8981\u5927\u91cf\u8bfb\u53d6\u78c1\u76d8\u4e0a\u7684\u9759\u6001\u6587\u4ef6\uff0c\u800c\u4e14\u670d\u52a1\u5668\u4e0a\u7684\u5185\u5b58\u8f83\u5c0f\uff0c\u4ee5\u81f3\u4e8e\u5927\u90e8\u5206\u7684\u8bf7\u6c42\u8bbf\u95ee\u9759\u6001\u6587\u4ef6\u65f6\u90fd\u5fc5\u987b\u8bfb\u53d6\u78c1\u76d8\uff0c\u800c\u4e0d\u662f\u5185\u5b58\u4e2d\u7684\u78c1\u76d8\u7f13\u5b58\uff0c\u90a3\u4e48\u78c1\u76d8I\/O\u8c03\u7528\u53ef\u80fd\u4f1a\u963b\u585e\u4f4fworker\u8fdb\u7a0b\u5c11\u91cf\u65f6\u523b\uff0c\u8fdb\u800c\u5bfc\u81f4\u670d\u52a1\u6574\u4f53\u6027\u80fd\u4e0b\u964d\u3002\u591aworker\u8fdb\u7a0b\u53ef\u4ee5\u5145\u5206\u5229\u7528\u591a\u6838\u7cfb\u7edf\u67b6\u6784\uff0c\u4f46\u82e5worker\u8fdb\u7a0b\u7684\u6570\u91cf\u591a\u4e8eCPU\u5185\u6838\u6570\uff0c\u90a3\u4e48\u4f1a\u589e\u5927\u8fdb\u7a0b\u95f4\u5207\u6362\u5e26\u6765\u7684\u6d88\u8017\uff08Linux\u662f\u62a2\u5360\u5f0f\u5185\u6838\uff09\u3002 \u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u7528\u6237\u914d\u7f6e\u4e0e\u5185\u6838\u6570\u76f8\u7b49\u7684worker\u8fdb\u7a0b\uff0c\u5e76\u4f7f\u7528<strong>worker_cpu_affinity<\/strong>\u914d\u7f6e\u6765\u7ed1\u5b9a<\/p>\n\n\n\n<p class=\"has-background has-luminous-vivid-amber-background-color wp-block-paragraph\">\u6ce8\u610f\uff1a worker_processes\u6700\u591a\u5f00\u542f8\u4e2a\uff0c8\u4e2a\u4ee5\u4e0a\u6027\u80fd\u63d0\u5347\u4e0d\u4f1a\u518d\u63d0\u5347\u4e86\uff0c\u800c\u4e14\u7a33\u5b9a\u6027\u53d8\u5f97\u66f4\u4f4e\uff0c\u6240\u4ee58\u4e2a\u8fdb\u7a0b\u591f\u7528\u4e86 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>worker_cpu_affinity:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">nginx\u9ed8\u8ba4\u662f\u6ca1\u6709\u5f00\u542f\u5229\u7528\u591a\u6838cpu\u7684\u914d\u7f6e\u7684\u3002\u9700\u8981\u901a\u8fc7\u589e\u52a0worker_cpu_affinity\u914d\u7f6e\u53c2\u6570\u6765\u5145\u5206\u5229\u7528\u591a\u6838cpu\uff0ccpu\u662f\u4efb\u52a1\u5904\u7406\uff0c\u5f53\u8ba1\u7b97\u6700\u8d39\u65f6\u7684\u8d44\u6e90\u7684\u65f6\u5019\uff0ccpu\u6838\u4f7f\u7528\u4e0a\u7684\u8d8a\u591a\uff0c\u6027\u80fd\u5c31\u8d8a\u597d <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff1a2\u6838cpu\uff0c\u5f00\u542f2\u4e2a\u8fdb\u7a0b\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"563\" height=\"125\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/21-2.png\" alt=\"\" class=\"wp-image-3432\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/21-2.png 563w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/21-2-300x67.png 300w\" sizes=\"auto, (max-width: 563px) 100vw, 563px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u56fe\u4e2d01\u8868\u793a\u7b2c\u4e00\u8fdb\u7a0b\u5bf9\u5e94\u7b2c\u4e00\u4e2acpu\u5185\u6838\uff0c10\u8868\u793a\u7b2c\u4e8c\u4e2a\u8fdb\u7a0b\u5bf9\u5e94\u7b2c\u4e8c\u4e2acpu\u5185\u6838\uff0c1\u8868\u793a\u5f00\u542f\uff0c0\u8868\u793a\u5173\u95ed<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff1a2\u6838cpu \uff0c\u5f00\u542f4\u4e2a\u8fdb\u7a0b\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"535\" height=\"127\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/22-2.png\" alt=\"\" class=\"wp-image-3433\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/22-2.png 535w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/22-2-300x71.png 300w\" sizes=\"auto, (max-width: 535px) 100vw, 535px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u56fe\u4e2d\u8868\u793a\u67092\u4e2a\u8fdb\u7a0b\u4f7f\u7528\u7b2c\u4e00\u4e2acpu\u5185\u6838\uff0c2\u4e2a\u8fdb\u7a0b\u4f7f\u7528\u7b2c\u4e8c\u4e2acpu\u5185\u6838<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff1a4\u6838cpu\uff0c\u5f00\u542f4\u4e2a\u8fdb\u7a0b\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"538\" height=\"107\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/23-2.png\" alt=\"\" class=\"wp-image-3434\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/23-2.png 538w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/23-2-300x60.png 300w\" sizes=\"auto, (max-width: 538px) 100vw, 538px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u56fe\u4e2d0001\u8868\u793a\u542f\u7528\u7b2c\u4e00\u4e2acpu\u5185\u6838\uff0c0010\u8868\u793a\u542f\u7528\u7b2c\u4e8c\u4e2acpu\u5185\u6838\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u5bf9\u5e94\u4e00\u4e2a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff1a4\u6838cpu\uff0c\u5f00\u542f2\u4e2a\u8fdb\u7a0b\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"528\" height=\"114\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/24-1.png\" alt=\"\" class=\"wp-image-3435\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/24-1.png 528w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/24-1-300x65.png 300w\" sizes=\"auto, (max-width: 528px) 100vw, 528px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u56fe\u4e2d0101\u8868\u793a\u7b2c\u4e00\u4e2a\u8fdb\u7a0b\u5bf9\u5e94\u7b2c\u4e00\u548c\u7b2c\u4e09\u4e2a\u5185\u6838\uff0c1010\u8868\u793a\u7b2c\u4e8c\u4e2a\u8fdb\u7a0b\u5bf9\u5e94\u7b2c\u4e8c\u4e2a\u548c\u7b2c\u56db\u4e2a\u5185\u6838<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff1a8\u6838cpu\uff0c\u5f00\u542f8\u4e2a\u8fdb\u7a0b\uff0c\u5982\u56fe:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"807\" height=\"148\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/25-1.png\" alt=\"\" class=\"wp-image-3436\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/25-1.png 807w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/25-1-300x55.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/25-1-768x141.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/25-1-600x110.png 600w\" sizes=\"auto, (max-width: 807px) 100vw, 807px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u56fe\u4e2d\u8868\u793a\u6bcf\u4e2a\u8fdb\u7a0b\u5bf9\u5e94\u4e00\u4e2a\u5185\u6838<\/p>\n\n\n\n<p class=\"has-background has-luminous-vivid-amber-background-color wp-block-paragraph\">\u6ce8\u610f\uff1a\u6570\u5b571\u7684\u4f4d\u7f6e\u521a\u597d\u5bf9\u5e94\u5f00\u542f\u7684cpu\u7684\u6838\u5fc3\u4f4d\u7f6e\uff0cwork_cpu_affinity\u540e\u9762\u8bbe\u7f6e\u7684\u6570\u91cf\u548cworker_processes\u7684\u6570\u91cf\u8981\u5bf9\u5e94<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2\u3001Nginx\u6700\u5927\u6253\u5f00\u6587\u4ef6\u6570<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">worker_rlimit_nofile 65535;   \/\/\u9ed8\u8ba4\u6ca1\u6709\uff0c\u9700\u8981\u6dfb\u52a0\uff0c\u4e0d\u5c5e\u4e8e\u4efb\u4f55\u533a\u5757\uff0c\u6dfb\u52a0\u4f4d\u7f6e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"540\" height=\"91\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/26-1.png\" alt=\"\" class=\"wp-image-3438\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/26-1.png 540w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/26-1-300x51.png 300w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u6307\u4ee4\u662f\u6307\u5f53\u4e00\u4e2anginx\u8fdb\u7a0b\u6253\u5f00\u7684\u6700\u591a\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u76ee\uff0c\u7406\u8bba\u503c\u5e94\u8be5\u662f\u6700\u591a\u6253\u5f00\u6587\u4ef6\u6570\uff08ulimit -n\uff09\u4e0enginx\u8fdb\u7a0b\u6570\u76f8\u9664\uff0c\u4f46\u662fnginx\u5206\u914d\u8bf7\u6c42\u5e76\u4e0d\u662f\u90a3\u4e48 \u5747\u5300\uff0c\u6240\u4ee5<strong>\u6700\u597d\u4e0eulimit -n\u7684\u503c\u4fdd\u6301\u4e00\u81f4 <\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\uff1a\u6587\u4ef6\u8d44\u6e90\u9650\u5236\u7684\u914d\u7f6e\u53ef\u4ee5\u5728\/etc\/security\/limits.conf\u8bbe\u7f6e\uff0c\u9488\u5bf9root\/user\u7b49\u5404\u4e2a\u7528\u6237\u6216\u8005*\u4ee3\u8868\u6240\u6709\u7528\u6237\u6765\u8bbe\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*   soft nofile   65535\n*   hard nofile   65535<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bbe\u7f6elimits.confg\u540e\u9700\u8981\u91cd\u65b0\u767b\u9646\u751f\u6548\uff0c\u6216\u8005\u91cd\u542f\u673a\u5668<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3\u3001Nginx\u4e8b\u4ef6\u5904\u7406\u6a21\u578b<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6253\u5f00nginx\u914d\u7f6e\u6587\u4ef6\uff0c\u539f\u6709\u7684\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"110\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/27-3.png\" alt=\"\" class=\"wp-image-3442\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/27-3.png 525w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/27-3-300x63.png 300w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f18\u5316\u540e\u7684\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"573\" height=\"142\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/27-4.png\" alt=\"\" class=\"wp-image-3443\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/27-4.png 573w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/27-4-300x74.png 300w\" sizes=\"auto, (max-width: 573px) 100vw, 573px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf4\u660e\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>use epoll\uff1a\u5f00\u542fepoll\u4e8b\u4ef6\u6a21\u578b\uff0c\u63d0\u9ad8\u5e76\u53d1\u8fde\u63a5\u548c\u975e\u6d3b\u52a8\u8fde\u63a5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u6548\u7387<\/li><li>worker_connections\uff1a \u5355\u4e2aworker\u8fdb\u7a0b\u5141\u8bb8\u5ba2\u6237\u7aef\u6700\u5927\u8fde\u63a5\u6570\uff0c\u8fd9\u4e2a\u6570\u503c\u4e00\u822c\u6839\u636e\u670d\u52a1\u5668\u6027\u80fd\u548c\u5185\u5b58\u6765\u5236\u5b9a\uff0c\u5b9e\u9645\u6700\u5927\u503c\u5c31\u662fworker\u8fdb\u7a0b\u6570\u4e58\u4ee5 work_connections\uff0c \u5b9e\u9645\u586b\u5165\u4e00\u4e2a65535\uff0c\u8db3\u591f\u4e86 <\/li><li>multi_accept on \uff1a nginx\u6536\u5230\u4e00\u4e2a\u65b0\u8fde\u63a5\u901a\u77e5\u540e\u63a5\u53d7\u5c3d\u53ef\u80fd\u591a\u7684\u8fde\u63a5\uff0c\u9ed8\u8ba4\u662fon\uff0c\u8bbe\u7f6e\u4e3aon\u540e\uff0c\u591a\u4e2aworker\u6309\u4e32\u884c\u65b9\u5f0f\u6765\u5904\u7406\u8fde\u63a5\uff0c\u4e5f\u5c31\u662f\u4e00\u4e2a\u8fde\u63a5\u53ea\u6709\u4e00 \u4e2aworker\u88ab\u5524\u9192\uff0c\u5176\u4ed6\u7684\u5904\u4e8e\u4f11\u7720\u72b6\u6001\uff0c\u8bbe\u7f6e\u4e3aoff\u540e\uff0c\u591a\u4e2aworker\u6309\u5e76\u884c\u65b9\u5f0f\u6765\u5904\u7406\u8fde\u63a5\uff0c\u4e5f\u5c31\u662f\u4e00\u4e2a\u8fde\u63a5\u4f1a\u5524\u9192\u6240\u6709\u7684worker\uff0c\u76f4\u5230\u8fde\u63a5\u5206\u914d\u5b8c\u6bd5\uff0c\u6ca1\u6709\u53d6\u5f97\u8fde\u63a5\u7684\u7ee7\u7eed\u4f11\u7720\u3002\u5f53\u4f60\u7684\u670d\u52a1\u5668\u8fde\u63a5\u6570\u4e0d\u591a\u65f6\uff0c\u5f00\u542f\u8fd9\u4e2a\u53c2\u6570\u4f1a\u8ba9<strong>\u8d1f\u8f7d\u6709\u4e00\u5b9a\u7684\u964d\u4f4e<\/strong>\uff0c\u4f46\u662f\u5f53\u670d\u52a1\u5668\u7684\u541e\u5410\u91cf\u5f88\u5927\u65f6\uff0c\u4e3a\u4e86\u6548\u7387\uff0c\u53ef\u4ee5\u5173\u95ed\u8fd9\u4e2a\u53c2\u6570\u3002 <\/li><li>accept_mutex on\uff1a \u9632\u6b62\u60ca\u7fa4\u73b0\u8c61\u53d1\u751f\uff0c\u9ed8\u8ba4\u4e3aon\uff0c\u53ef\u4e0d\u7528\u914d\u7f6e\uff0cnginx\u5b89\u88c5\u597d\u4e4b\u540e\u9ed8\u8ba4\u5c31\u662fon <\/li><\/ul>\n\n\n\n<p class=\"has-background has-luminous-vivid-amber-background-color wp-block-paragraph\"><strong>\u60ca\u7fa4\u73b0\u8c61<\/strong>\uff1a \u5728\u5efa\u7acb\u8fde\u63a5\u7684\u65f6\u5019\uff0cNginx\u5904\u4e8e\u5145\u5206\u53d1\u6325\u591a\u6838CPU\u67b6\u6784\u6027\u80fd\u7684\u8003\u8651\uff0c\u4f7f\u7528\u4e86\u591a\u4e2aworker\u5b50\u8fdb\u7a0b\u76d1\u542c\u76f8\u540c\u7aef\u53e3\u7684\u8bbe\u8ba1\uff0c\u8fd9\u6837\u591a\u4e2a\u5b50\u8fdb\u7a0b\u5728accept\u5efa\u7acb\u65b0\u8fde\u63a5\u65f6\u4f1a\u6709\u4e89\u62a2\uff0c\u8fd9\u4f1a\u5e26\u6765\u8457\u540d\u7684\u201c\u60ca\u7fa4\u201d\u95ee\u9898\uff0c\u5b50\u8fdb\u7a0b\u6570\u91cf\u8d8a\u591a\u8d8a\u660e\u663e\uff0c\u8fd9\u4f1a\u9020\u6210\u7cfb\u7edf\u6027\u80fd\u7684\u4e0b\u964d\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4\u3001\u5f00\u542f\u9ad8\u6548\u4f20\u8f93\u6a21\u5f0f<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"597\" height=\"168\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/29.png\" alt=\"\" class=\"wp-image-3446\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/29.png 597w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/29-300x84.png 300w\" sizes=\"auto, (max-width: 597px) 100vw, 597px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li> sendfile on\uff1a\u5f00\u542f\u9ad8\u6548\u6587\u4ef6\u4f20\u8f93\u6a21\u5f0f\uff0csendfile\u6307\u4ee4\u6307\u5b9anginx\u662f\u5426\u8c03\u7528sendfile\u51fd\u6570\u6765\u8f93\u51fa\u6587\u4ef6\uff0c\u5bf9\u4e8e\u666e\u901a\u5e94\u7528\u8bbe\u4e3a on\uff0c\u5982\u679c\u7528\u6765\u8fdb\u884c\u4e0b\u8f7d\u7b49\u5e94\u7528\u78c1\u76d8IO\u91cd\u8d1f\u8f7d\u5e94\u7528\uff0c\u53ef\u8bbe\u7f6e\u4e3aoff\uff0c\u4ee5\u5e73\u8861\u78c1\u76d8\u4e0e\u7f51\u7edcI\/O\u5904\u7406\u901f\u5ea6\uff0c\u964d\u4f4e\u7cfb\u7edf\u7684\u8d1f\u8f7d\u3002\u6ce8\u610f\uff1a\u5982\u679c\u56fe\u7247\u663e\u793a\u4e0d\u6b63\u5e38\u628a\u8fd9\u4e2a\u6539\u6210off\u3002 <\/li><li> tcp_nopush on\uff1a\u5fc5\u987b\u5728<strong>sendfile\u5f00\u542f\u6a21\u5f0f\u624d\u6709\u6548<\/strong>\uff0c\u9632\u6b62\u7f51\u8def\u963b\u585e\uff0c\u79ef\u6781\u7684\u51cf\u5c11\u7f51\u7edc\u62a5\u6587\u6bb5\u7684\u6570\u91cf\uff08\u5c06\u54cd\u5e94\u5934\u548c\u6b63\u6587\u7684\u5f00\u59cb\u90e8\u5206\u4e00\u8d77\u53d1\u9001\uff0c\u800c\u4e0d\u4e00\u4e2a\u63a5\u4e00\u4e2a\u7684\u53d1\u9001\u3002\uff09 <\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5\u3001\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u4e3b\u8981\u76ee\u7684\u662f\u4fdd\u62a4\u670d\u52a1\u5668\u8d44\u6e90\uff0cCPU\uff0c\u5185\u5b58\uff0c\u63a7\u5236\u8fde\u63a5\u6570\uff0c\u56e0\u4e3a\u5efa\u7acb\u8fde\u63a5\u4e5f\u662f\u9700\u8981\u6d88\u8017\u8d44\u6e90\u7684\u3002\n\nkeepalive_timeout 60;\ntcp_nodelay on;\nclient_header_buffer_size 4k;\nopen_file_cache max=102400 inactive=20s;\nopen_file_cache_valid 30s;\nopen_file_cache_min_uses 1;\nclient_header_timeout 15;\nclient_body_timeout 15;\nreset_timedout_connection on;\nsend_timeout 15;\nserver_tokens off;\nclient_max_body_size 10m;\nkeepalived_timeout \uff1a\u5ba2\u6237\u7aef\u8fde\u63a5\u4fdd\u6301\u4f1a\u8bdd\u8d85\u65f6\u65f6\u95f4\uff0c\u8d85\u8fc7\u8fd9\u4e2a\u65f6\u95f4\uff0c\u670d\u52a1\u5668\u65ad\u5f00\u8fd9\u4e2a\u94fe\u63a5\u3002\n\ntcp_nodelay\uff1a\u4e5f\u662f\u9632\u6b62\u7f51\u7edc\u963b\u585e\uff0c\u4e0d\u8fc7\u8981\u5305\u6db5\u5728keepalived\u53c2\u6570\u624d\u6709\u6548\u3002\n\nclient_header_buffer_size 4k\uff1a\u5ba2\u6237\u7aef\u8bf7\u6c42\u5934\u90e8\u7684\u7f13\u51b2\u533a\u5927\u5c0f\uff0c\u8fd9\u4e2a\u53ef\u4ee5\u6839\u636e\u4f60\u7684\u7cfb\u7edf\u5206\u9875\u5927\u5c0f\u6765\u8bbe\u7f6e\uff0c\u4e00\u822c\u4e00\u4e2a\u8bf7\u6c42\u5934\u7684\u5927\u5c0f\u4e0d\u4f1a\u8d85\u8fc7 1k\uff0c\u4e0d\u8fc7\u7531\u4e8e\u4e00\u822c\u7cfb\u7edf\u5206\u9875\u90fd\u8981\u5927\u4e8e1k\uff0c\u6240\u4ee5\u8fd9\u91cc\u8bbe\u7f6e\u4e3a\u5206\u9875\u5927\u5c0f\u3002\u5206\u9875\u5927\u5c0f\u53ef\u4ee5\u7528\u547d\u4ee4getconf PAGESIZE\u53d6\u5f97\u3002\n\nopen_file_cache max=102400 inactive=20s \uff1a\u8fd9\u4e2a\u5c06\u4e3a\u6253\u5f00\u6587\u4ef6\u6307\u5b9a\u7f13\u5b58\uff0c\u9ed8\u8ba4\u662f\u6ca1\u6709\u542f\u7528\u7684\uff0cmax\u6307\u5b9a\u7f13\u5b58\u6570\u91cf\uff0c\u5efa\u8bae\u548c\u6253\u5f00\u6587\u4ef6\u6570\u4e00\u81f4\uff0cinactive \u662f\u6307\u7ecf\u8fc7\u591a\u957f\u65f6\u95f4\u6587\u4ef6\u6ca1\u88ab\u8bf7\u6c42\u540e\u5220\u9664\u7f13\u5b58\u3002\n\nopen_file_cache_valid 30s\uff1a\u8fd9\u4e2a\u662f\u6307\u591a\u957f\u65f6\u95f4\u68c0\u67e5\u4e00\u6b21\u7f13\u5b58\u7684\u6709\u6548\u4fe1\u606f\u3002\n\nopen_file_cache_min_uses 1 \uff1aopen_file_cache\u6307\u4ee4\u4e2d\u7684inactive \u53c2\u6570\u65f6\u95f4\u5185\u6587\u4ef6\u7684\u6700\u5c11\u4f7f\u7528\u6b21\u6570\uff0c\u5982\u679c\u8d85\u8fc7\u8fd9\u4e2a\u6570\u5b57\uff0c\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e00\u76f4\u662f\u5728\u7f13\u5b58\u4e2d\u6253\u5f00\u7684\uff0c\u5982\u4e0a\u4f8b\uff0c\u5982\u679c\u6709\u4e00\u4e2a\u6587\u4ef6\u5728inactive \u65f6\u95f4\u5185\u4e00\u6b21\u6ca1\u88ab\u4f7f\u7528\uff0c\u5b83\u5c06\u88ab\u79fb\u9664\u3002\n\nclient_header_timeout \uff1a \u8bbe\u7f6e\u8bf7\u6c42\u5934\u7684\u8d85\u65f6\u65f6\u95f4\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u628a\u8fd9\u4e2a\u8bbe\u7f6e\u4f4e\u4e9b\uff0c\u5982\u679c\u8d85\u8fc7\u8fd9\u4e2a\u65f6\u95f4\u6ca1\u6709\u53d1\u9001\u4efb\u4f55\u6570\u636e\uff0cnginx\u5c06\u8fd4\u56derequest time out\u7684\u9519\u8bef\u3002\n\nclient_body_timeout\u8bbe\u7f6e\u8bf7\u6c42\u4f53\u7684\u8d85\u65f6\u65f6\u95f4\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u628a\u8fd9\u4e2a\u8bbe\u7f6e\u4f4e\u4e9b\uff0c\u8d85\u8fc7\u8fd9\u4e2a\u65f6\u95f4\u6ca1\u6709\u53d1\u9001\u4efb\u4f55\u6570\u636e\uff0c\u548c\u4e0a\u9762\u4e00\u6837\u7684\u9519\u8bef\u63d0\u793a\u3002\n\nreset_timeout_connection \uff1a\u544a\u8bc9nginx\u5173\u95ed\u4e0d\u54cd\u5e94\u7684\u5ba2\u6237\u7aef\u8fde\u63a5\u3002\u8fd9\u5c06\u4f1a\u91ca\u653e\u90a3\u4e2a\u5ba2\u6237\u7aef\u6240\u5360\u6709\u7684\u5185\u5b58\u7a7a\u95f4\u3002\n\nsend_timeout \uff1a\u54cd\u5e94\u5ba2\u6237\u7aef\u8d85\u65f6\u65f6\u95f4\uff0c\u8fd9\u4e2a\u8d85\u65f6\u65f6\u95f4\u4ec5\u9650\u4e8e\u4e24\u4e2a\u6d3b\u52a8\u4e4b\u95f4\u7684\u65f6\u95f4\uff0c\u5982\u679c\u8d85\u8fc7\u8fd9\u4e2a\u65f6\u95f4\uff0c\u5ba2\u6237\u7aef\u6ca1\u6709\u4efb\u4f55\u6d3b\u52a8\uff0cnginx\u5173\u95ed\u8fde\u63a5\u3002\n\nserver_tokens \uff1a\u5e76\u4e0d\u4f1a\u8ba9nginx\u6267\u884c\u7684\u901f\u5ea6\u66f4\u5feb\uff0c\u4f46\u5b83\u53ef\u4ee5\u5173\u95ed\u5728\u9519\u8bef\u9875\u9762\u4e2d\u7684nginx\u7248\u672c\u6570\u5b57\uff0c\u8fd9\u6837\u5bf9\u4e8e\u5b89\u5168\u6027\u662f\u6709\u597d\u5904\u7684\u3002\n\nclient_max_body_size\uff1a\u4e0a\u4f20\u6587\u4ef6\u5927\u5c0f\u9650\u5236\u3002<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>6\u3001fastcgi \u8c03\u4f18<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fastcgi_connect_timeout 600;\nfastcgi_send_timeout 600;\nfastcgi_read_timeout 600;\nfastcgi_buffer_size 64k;\nfastcgi_buffers 4 64k;\nfastcgi_busy_buffers_size 128k;\nfastcgi_temp_file_write_size 128k;\nfastcgi_temp_path\/usr\/local\/nginx1.10\/nginx_tmp;\nfastcgi_intercept_errors on;\nfastcgi_cache_path\/usr\/local\/nginx1.10\/fastcgi_cache levels=1:2 keys_zone=cache_fastcgi:128minactive=1d max_size=10g;\nfastcgi_connect_timeout 600 \uff1a\u6307\u5b9a\u8fde\u63a5\u5230\u540e\u7aefFastCGI\u7684\u8d85\u65f6\u65f6\u95f4\u3002\n\nfastcgi_send_timeout 600 \uff1a\u5411FastCGI\u4f20\u9001\u8bf7\u6c42\u7684\u8d85\u65f6\u65f6\u95f4\u3002\n\nfastcgi_read_timeout 600 \uff1a\u6307\u5b9a\u63a5\u6536FastCGI\u5e94\u7b54\u7684\u8d85\u65f6\u65f6\u95f4\u3002\n\nfastcgi_buffer_size 64k \uff1a\u6307\u5b9a\u8bfb\u53d6FastCGI\u5e94\u7b54\u7b2c\u4e00\u90e8\u5206\u9700\u8981\u7528\u591a\u5927\u7684\u7f13\u51b2\u533a\uff0c\u9ed8\u8ba4\u7684\u7f13\u51b2\u533a\u5927\u5c0f\u4e3a\u3002fastcgi_buffers\u6307\u4ee4\u4e2d\u7684\u6bcf\u5757\u5927\u5c0f\uff0c\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u503c\u8bbe\u7f6e\u66f4\u5c0f\u3002\n\nfastcgi_buffers 4 64k \uff1a\u6307\u5b9a\u672c\u5730\u9700\u8981\u7528\u591a\u5c11\u548c\u591a\u5927\u7684\u7f13\u51b2\u533a\u6765\u7f13\u51b2FastCGI\u7684\u5e94\u7b54\u8bf7\u6c42\uff0c\u5982\u679c\u4e00\u4e2aphp\u811a\u672c\u6240\u4ea7\u751f\u7684\u9875\u9762\u5927\u5c0f\u4e3a256KB\uff0c\u90a3\u4e48\u4f1a\u5206\u914d4\u4e2a64KB\u7684\u7f13\u51b2\u533a\u6765\u7f13\u5b58\uff0c\u5982\u679c\u9875\u9762\u5927\u5c0f\u5927\u4e8e256KB\uff0c\u90a3\u4e48\u5927\u4e8e256KB\u7684\u90e8\u5206\u4f1a\u7f13\u5b58\u5230fastcgi_temp_path\u6307\u5b9a\u7684\u8def\u5f84\u4e2d\uff0c\u4f46\u662f\u8fd9\u5e76\u4e0d\u662f\u597d\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5185\u5b58\u4e2d\u7684\u6570\u636e\u5904\u7406\u901f\u5ea6\u8981\u5feb\u4e8e\u78c1\u76d8\u3002\u4e00\u822c\u8fd9\u4e2a\u503c\u5e94\u8be5\u4e3a\u7ad9\u70b9\u4e2dphp\u811a\u672c\u6240\u4ea7\u751f\u7684\u9875\u9762\u5927\u5c0f\u7684\u4e2d\u95f4\u503c\uff0c\u5982\u679c\u7ad9\u70b9\u5927\u90e8\u5206\u811a\u672c\u6240\u4ea7\u751f\u7684\u9875\u9762\u5927\u5c0f\u4e3a256KB\uff0c\u90a3\u4e48\u53ef\u4ee5\u628a\u8fd9\u4e2a\u503c\u8bbe\u7f6e\u4e3a\u201c8 32K\u201d\u3001\u201c4 64k\u201d\u7b49\u3002\n\nfastcgi_busy_buffers_size 128k \uff1a\u5efa\u8bae\u8bbe\u7f6e\u4e3afastcgi_buffers\u7684\u4e24\u500d\uff0c\u7e41\u5fd9\u65f6\u5019\u7684buffer\u3002\n\nfastcgi_temp_file_write_size 128k \uff1a\u5728\u5199\u5165fastcgi_temp_path\u65f6\u5c06\u7528\u591a\u5927\u7684\u6570\u636e\u5757\uff0c\u9ed8\u8ba4\u503c\u662ffastcgi_buffers\u7684\u4e24\u500d\uff0c\u8be5\u6570\u503c\u8bbe\u7f6e\u5c0f\u65f6\u82e5\u8d1f\u8f7d\u4e0a\u6765\u65f6\u53ef\u80fd\u62a5502BadGateway\u3002\n\nfastcgi_temp_path  \uff1a\u7f13\u5b58\u4e34\u65f6\u76ee\u5f55\u3002\n\nfastcgi_intercept_errors on \uff1a\u8fd9\u4e2a\u6307\u4ee4\u6307\u5b9a\u662f\u5426\u4f20\u90124xx\u548c5xx\u9519\u8bef\u4fe1\u606f\u5230\u5ba2\u6237\u7aef\uff0c\u6216\u8005\u5141\u8bb8nginx\u4f7f\u7528error_page\u5904\u7406\u9519\u8bef\u4fe1\u606f\u3002\u6ce8\uff1a\u9759\u6001\u6587\u4ef6\u4e0d\u5b58\u5728\u4f1a\u8fd4\u56de404\u9875\u9762\uff0c\u4f46\u662fphp\u9875\u9762\u5219\u8fd4\u56de\u7a7a\u767d\u9875\uff01\n\nfastcgi_cache_path \/usr\/local\/nginx1.10\/fastcgi_cachelevels=1:2 keys_zone=cache_fastcgi:128minactive=1d max_size=10g \uff1afastcgi_cache\u7f13\u5b58\u76ee\u5f55\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u76ee\u5f55\u5c42\u7ea7\uff0c\u6bd4\u59821:2\u4f1a\u751f\u621016*256\u4e2a\u5b50\u76ee\u5f55\uff0ccache_fastcgi\u662f\u8fd9\u4e2a\u7f13\u5b58\u7a7a\u95f4\u7684\u540d\u5b57\uff0ccache\u662f\u7528\u591a\u5c11\u5185\u5b58\uff08\u8fd9\u6837\u70ed\u95e8\u7684\u5185\u5bb9nginx\u76f4\u63a5\u653e\u5185\u5b58\uff0c\u63d0\u9ad8\u8bbf\u95ee\u901f\u5ea6\uff09\uff0cinactive\u8868\u793a\u9ed8\u8ba4\u5931\u6548\u65f6\u95f4\uff0c\u5982\u679c\u7f13\u5b58\u6570\u636e\u5728\u5931\u6548\u65f6\u95f4\u5185\u6ca1\u6709\u88ab\u8bbf\u95ee,\u5c06\u88ab\u5220\u9664\uff0cmax_size\u8868\u793a\u6700\u591a\u7528\u591a\u5c11\u786c\u76d8\u7a7a\u95f4\u3002\n\nfastcgi_cache cache_fastcgi \uff1a#\u8868\u793a\u5f00\u542fFastCGI\u7f13\u5b58\u5e76\u4e3a\u5176\u6307\u5b9a\u4e00\u4e2a\u540d\u79f0\u3002\u5f00\u542f\u7f13\u5b58\u975e\u5e38\u6709\u7528\uff0c\u53ef\u4ee5\u6709\u6548\u964d\u4f4eCPU\u7684\u8d1f\u8f7d\uff0c\u5e76\u4e14\u9632\u6b62502\u7684\u9519\u8bef\u653e\u751f\u3002cache_fastcgi\u4e3aproxy_cache_path\u6307\u4ee4\u521b\u5efa\u7684\u7f13\u5b58\u533a\u540d\u79f0\u3002\n\nfastcgi_cache_valid 200 302 1h \uff1a#\u7528\u6765\u6307\u5b9a\u5e94\u7b54\u4ee3\u7801\u7684\u7f13\u5b58\u65f6\u95f4\uff0c\u5b9e\u4f8b\u4e2d\u7684\u503c\u8868\u793a\u5c06200\u548c302\u5e94\u7b54\u7f13\u5b58\u4e00\u5c0f\u65f6\uff0c\u8981\u548cfastcgi_cache\u914d\u5408\u4f7f\u7528\u3002\n\nfastcgi_cache_valid 301 1d \uff1a\u5c06301\u5e94\u7b54\u7f13\u5b58\u4e00\u5929\u3002\n\nfastcgi_cache_valid any 1m \uff1a\u5c06\u5176\u4ed6\u5e94\u7b54\u7f13\u5b58\u4e3a1\u5206\u949f\u3002\n\nfastcgi_cache_min_uses 1 \uff1a\u8be5\u6307\u4ee4\u7528\u4e8e\u8bbe\u7f6e\u7ecf\u8fc7\u591a\u5c11\u6b21\u8bf7\u6c42\u7684\u76f8\u540cURL\u5c06\u88ab\u7f13\u5b58\u3002\n\nfastcgi_cache_key http:\/\/$host$request_uri \uff1a\u8be5\u6307\u4ee4\u7528\u6765\u8bbe\u7f6eweb\u7f13\u5b58\u7684Key\u503c,nginx\u6839\u636eKey\u503cmd5\u54c8\u5e0c\u5b58\u50a8.\u4e00\u822c\u6839\u636e$host(\u57df\u540d)\u3001$request_uri(\u8bf7\u6c42\u7684\u8def\u5f84)\u7b49\u53d8\u91cf\u7ec4\u5408\u6210proxy_cache_key \u3002\n\nfastcgi_pass  \uff1a\u6307\u5b9aFastCGI\u670d\u52a1\u5668\u76d1\u542c\u7aef\u53e3\u4e0e\u5730\u5740\uff0c\u53ef\u4ee5\u662f\u672c\u673a\u6216\u8005\u5176\u5b83\u3002\n\n\u603b\u7ed3\uff1a\n\nnginx\u7684\u7f13\u5b58\u529f\u80fd\u6709\uff1aproxy_cache \/ fastcgi_cache\n\nproxy_cache\u7684\u4f5c\u7528\u662f\u7f13\u5b58\u540e\u7aef\u670d\u52a1\u5668\u7684\u5185\u5bb9\uff0c\u53ef\u80fd\u662f\u4efb\u4f55\u5185\u5bb9\uff0c\u5305\u62ec\u9759\u6001\u7684\u548c\u52a8\u6001\u3002\n\nfastcgi_cache\u7684\u4f5c\u7528\u662f\u7f13\u5b58fastcgi\u751f\u6210\u7684\u5185\u5bb9\uff0c\u5f88\u591a\u60c5\u51b5\u662fphp\u751f\u6210\u7684\u52a8\u6001\u7684\u5185\u5bb9\u3002\n\nproxy_cache\u7f13\u5b58\u51cf\u5c11\u4e86nginx\u4e0e\u540e\u7aef\u901a\u4fe1\u7684\u6b21\u6570\uff0c\u8282\u7701\u4e86\u4f20\u8f93\u65f6\u95f4\u548c\u540e\u7aef\u5bbd\u5e26\u3002\n\nfastcgi_cache\u7f13\u5b58\u51cf\u5c11\u4e86nginx\u4e0ephp\u7684\u901a\u4fe1\u7684\u6b21\u6570\uff0c\u66f4\u51cf\u8f7b\u4e86php\u548c\u6570\u636e\u5e93(mysql)\u7684\u538b\u529b\u3002<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>7\u3001gzip \u8c03\u4f18<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u4f7f\u7528gzip\u538b\u7f29\u529f\u80fd\uff0c\u53ef\u80fd\u4e3a\u6211\u4eec\u8282\u7ea6\u5e26\u5bbd\uff0c\u52a0\u5feb\u4f20\u8f93\u901f\u5ea6\uff0c\u6709\u66f4\u597d\u7684\u4f53\u9a8c\uff0c\u4e5f\u4e3a\u6211\u4eec\u8282\u7ea6\u6210\u672c\uff0c\u6240\u4ee5\u8bf4\u8fd9\u662f\u4e00\u4e2a\u91cd\u70b9\u3002\n\nNginx\u542f\u7528\u538b\u7f29\u529f\u80fd\u9700\u8981\u4f60\u6765ngx_http_gzip_module\u6a21\u5757\uff0capache\u4f7f\u7528\u7684\u662fmod_deflate\u3002\n\n\u4e00\u822c\u6211\u4eec\u9700\u8981\u538b\u7f29\u7684\u5185\u5bb9\u6709\uff1a\u6587\u672c\uff0cjs\uff0chtml\uff0ccss\uff0c\u5bf9\u4e8e\u56fe\u7247\uff0c\u89c6\u9891\uff0cflash\u4ec0\u4e48\u7684\u4e0d\u538b\u7f29\uff0c\u540c\u65f6\u4e5f\u8981\u6ce8\u610f\uff0c\u6211\u4eec\u4f7f\u7528gzip\u7684\u529f\u80fd\u662f\u9700\u8981\u6d88\u8017CPU\u7684\uff01\n\ngzip on;\ngzip_min_length 2k;\ngzip_buffers   4 32k;\ngzip_http_version 1.1;\ngzip_comp_level 6;\ngzip_typestext\/plain text\/css text\/javascriptapplication\/json application\/javascript application\/x-javascriptapplication\/xml;\ngzip_vary on;\ngzip_proxied any;\n\u8bf4\u660e\uff1a\ngzip on;   #\u5f00\u542f\u538b\u7f29\u529f\u80fd\ngzip_min_length 1k \uff1a\u8bbe\u7f6e\u5141\u8bb8\u538b\u7f29\u7684\u9875\u9762\u6700\u5c0f\u5b57\u8282\u6570\uff0c\u9875\u9762\u5b57\u8282\u6570\u4eceheader\u5934\u7684Content-Length\u4e2d\u83b7\u53d6\uff0c\u9ed8\u8ba4\u503c\u662f0\uff0c\u4e0d\u7ba1\u9875\u9762\u591a\u5927\u90fd\u8fdb\u884c\u538b\u7f29\uff0c\u5efa\u8bae\u8bbe\u7f6e\u6210\u5927\u4e8e1K\uff0c\u5982\u679c\u5c0f\u4e0e1K\u53ef\u80fd\u4f1a\u8d8a\u538b\u8d8a\u5927\u3002\n\ngzip_buffers 4 32k \uff1a\u538b\u7f29\u7f13\u51b2\u533a\u5927\u5c0f\uff0c\u8868\u793a\u7533\u8bf74\u4e2a\u5355\u4f4d\u4e3a32K\u7684\u5185\u5b58\u4f5c\u4e3a\u538b\u7f29\u7ed3\u679c\u6d41\u7f13\u5b58\uff0c\u9ed8\u8ba4\u503c\u662f\u7533\u8bf7\u4e0e\u539f\u59cb\u6570\u636e\u5927\u5c0f\u76f8\u540c\u7684\u5185\u5b58\u7a7a\u95f4\u6765\u5b58\u50a8gzip\u538b\u7f29\u7ed3\u679c\u3002\n\ngzip_http_version 1.1 \uff1a\u538b\u7f29\u7248\u672c\uff0c\u7528\u4e8e\u8bbe\u7f6e\u8bc6\u522bHTTP\u534f\u8bae\u7248\u672c\uff0c\u9ed8\u8ba4\u662f1.1\uff0c\u76ee\u524d\u5927\u90e8\u5206\u6d4f\u89c8\u5668\u5df2\u7ecf\u652f\u6301GZIP\u89e3\u538b\uff0c\u4f7f\u7528\u9ed8\u8ba4\u5373\u53ef\u3002\n\ngzip_comp_level 6 \uff1a\u538b\u7f29\u6bd4\u4f8b\uff0c\u7528\u6765\u6307\u5b9aGZIP\u538b\u7f29\u6bd4\uff0c1\u538b\u7f29\u6bd4\u6700\u5c0f\uff0c\u5904\u7406\u901f\u5ea6\u6700\u5feb\uff0c9\u538b\u7f29\u6bd4\u6700\u5927\uff0c\u4f20\u8f93\u901f\u5ea6\u5feb\uff0c\u4f46\u662f\u5904\u7406\u6162\uff0c\u4e5f\u6bd4\u8f83\u6d88\u8017CPU\u8d44\u6e90\u3002\n\ngzip_types text\/css text\/xml application\/javascript \uff1a\u7528\u6765\u6307\u5b9a\u538b\u7f29\u7684\u7c7b\u578b\uff0c\u2018text\/html\u2019\u7c7b\u578b\u603b\u662f\u4f1a\u88ab\u538b\u7f29\u3002\u9ed8\u8ba4\u503c: gzip_types text\/html (\u9ed8\u8ba4\u4e0d\u5bf9js\/css\u6587\u4ef6\u8fdb\u884c\u538b\u7f29)\n\n\u538b\u7f29\u7c7b\u578b\uff0c\u5339\u914dMIME\u578b\u8fdb\u884c\u538b\u7f29\uff1b\n\n\u4e0d\u80fd\u7528\u901a\u914d\u7b26 text\/*\uff1b\n\ntext\/html\u9ed8\u8ba4\u5df2\u7ecf\u538b\u7f29 (\u65e0\u8bba\u662f\u5426\u6307\u5b9a)\uff1b\n\n\u8bbe\u7f6e\u54ea\u538b\u7f29\u79cd\u6587\u672c\u6587\u4ef6\u53ef\u53c2\u8003 conf\/mime.types\u3002\n\ngzip_vary on \uff1avaryheader\u652f\u6301\uff0c\u6539\u9009\u9879\u53ef\u4ee5\u8ba9\u524d\u7aef\u7684\u7f13\u5b58\u670d\u52a1\u5668\u7f13\u5b58\u7ecf\u8fc7GZIP\u538b\u7f29\u7684\u9875\u9762\uff0c\u4f8b\u5982\u7528Squid\u7f13\u5b58\u7ecf\u8fc7nginx\u538b\u7f29\u7684\u6570\u636e\u3002<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>8\u3001expires \u7f13\u5b58\u8c03\u4f18<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u7f13\u5b58\uff0c\u4e3b\u8981\u9488\u5bf9\u4e8e\u56fe\u7247\uff0ccss\uff0cjs\u7b49\u5143\u7d20\u66f4\u6539\u673a\u4f1a\u6bd4\u8f83\u5c11\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\uff0c\u7279\u522b\u662f\u56fe\u7247\uff0c\u5360\u7528\u5e26\u5bbd\u5927\uff0c\u6211\u4eec\u5b8c\u5168\u53ef\u4ee5\u8bbe\u7f6e\u56fe\u7247\u5728\u6d4f\u89c8\u5668\u672c\u5730\u7f13\u5b58365d\uff0ccss\uff0cjs\uff0chtml\u53ef\u4ee5\u7f13\u5b58\u4e2a10\u6765\u5929\uff0c\u8fd9\u6837\u7528\u6237\u7b2c\u4e00\u6b21\u6253\u5f00\u52a0\u8f7d\u6162\u4e00\u70b9\uff0c\u7b2c\u4e8c\u6b21\uff0c\u5c31\u975e\u5e38\u5feb\u4e86\uff01\u7f13\u5b58\u7684\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981\u5c06\u9700\u8981\u7f13\u5b58\u7684\u62d3\u5c55\u540d\u5217\u51fa\u6765\uff0c Expires\u7f13\u5b58\u914d\u7f6e\u5728server\u5b57\u6bb5\u91cc\u9762\u3002\n\nlocation ~* \\.(ico|jpe?g|gif|png|bmp|swf|flv)$ {\nexpires 30d;\n#log_not_found off;\naccess_log off;\n}\n\nlocation ~* \\.(js|css)$ {\nexpires 7d;\nlog_not_found off;\naccess_log off;\n}\n\u6ce8\uff1alog_not_found off;\u662f\u5426\u5728error_log\u4e2d\u8bb0\u5f55\u4e0d\u5b58\u5728\u7684\u9519\u8bef\u3002\u9ed8\u8ba4\u662f\u3002\n\n\u603b\u7ed3\uff1a\n\nexpire\u529f\u80fd\u4f18\u70b9\uff1a\n\nexpires\u53ef\u4ee5\u964d\u4f4e\u7f51\u7ad9\u8d2d\u4e70\u7684\u5e26\u5bbd\uff0c\u8282\u7ea6\u6210\u672c\uff1b\n\n\u540c\u65f6\u63d0\u5347\u7528\u6237\u8bbf\u95ee\u4f53\u9a8c\uff1b\n\n\u51cf\u8f7b\u670d\u52a1\u7684\u538b\u529b\uff0c\u8282\u7ea6\u670d\u52a1\u5668\u6210\u672c\uff0c\u662fweb\u670d\u52a1\u975e\u5e38\u91cd\u8981\u7684\u529f\u80fd\u3002\n\nexpire\u529f\u80fd\u7f3a\u70b9\uff1a\n\n\u88ab\u7f13\u5b58\u7684\u9875\u9762\u6216\u6570\u636e\u66f4\u65b0\u4e86\uff0c\u7528\u6237\u770b\u5230\u7684\u53ef\u80fd\u8fd8\u662f\u65e7\u7684\u5185\u5bb9\uff0c\u53cd\u800c\u5f71\u54cd\u7528\u6237\u4f53\u9a8c\u3002\n\n\u89e3\u51b3\u529e\u6cd5\uff1a\u7b2c\u4e00\u4e2a\u7f29\u77ed\u7f13\u5b58\u65f6\u95f4\uff0c\u4f8b\u5982\uff1a1\u5929\uff0c\u4f46\u4e0d\u5f7b\u5e95\uff0c\u9664\u975e\u66f4\u65b0\u9891\u7387\u5927\u4e8e1\u5929\uff1b\u7b2c\u4e8c\u4e2a\u5bf9\u7f13\u5b58\u7684\u5bf9\u8c61\u6539\u540d\u3002\n\n\u7f51\u7ad9\u4e0d\u5e0c\u671b\u88ab\u7f13\u5b58\u7684\u5185\u5bb9\uff1a\n\n\u7f51\u7ad9\u6d41\u91cf\u7edf\u8ba1\u5de5\u5177\uff1b\n\n\u66f4\u65b0\u9891\u7e41\u7684\u6587\u4ef6\uff08google\u7684logo\uff09\u3002<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>9\u3001\u9632\u76d7\u94fe<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u9632\u6b62\u522b\u4eba\u76f4\u63a5\u4ece\u4f60\u7f51\u7ad9\u5f15\u7528\u56fe\u7247\u7b49\u94fe\u63a5\uff0c\u6d88\u8017\u4e86\u4f60\u7684\u8d44\u6e90\u548c\u7f51\u7edc\u6d41\u91cf\uff0c\u90a3\u4e48\u6211\u4eec\u7684\u89e3\u51b3\u529e\u6cd5\u7531\u51e0\u79cd\uff1a\n\n\u6c34\u5370\uff0c\u54c1\u724c\u5ba3\u4f20\uff0c\u4f60\u7684\u5e26\u5bbd\uff0c\u670d\u52a1\u5668\u8db3\u591f\uff1b\n\n\u9632\u706b\u5899\uff0c\u76f4\u63a5\u63a7\u5236\uff0c\u524d\u63d0\u662f\u4f60\u77e5\u9053IP\u6765\u6e90\uff1b\n\n\u9632\u76d7\u94fe\u7b56\u7565\u4e0b\u9762\u7684\u65b9\u6cd5\u662f\u76f4\u63a5\u7ed9\u4e88404\u7684\u9519\u8bef\u63d0\u793a\u3002\n\nlocation ~*^.+\\.(jpg|gif|png|swf|flv|wma|wmv|asf|mp3|mmf|zip|rar)$ {\nvalid_referers noneblocked www.benet.com benet.com;\nif($invalid_referer) {\n  #return 302 http:\/\/www.benet.com\/img\/nolink.jpg;\n  return 404;\n  break;\n}\naccess_log off;\n}\n\u53c2\u6570\u53ef\u4ee5\u4f7f\u5982\u4e0b\u5f62\u5f0f\uff1a\n\nnone  \uff1a\u610f\u601d\u662f\u4e0d\u5b58\u5728\u7684Referer\u5934(\u8868\u793a\u7a7a\u7684\uff0c\u4e5f\u5c31\u662f\u76f4\u63a5\u8bbf\u95ee\uff0c\u6bd4\u5982\u76f4\u63a5\u5728\u6d4f\u89c8\u5668\u6253\u5f00\u4e00\u4e2a\u56fe\u7247)\u3002\n\nblocked  \uff1a\u610f\u4e3a\u6839\u636e\u9632\u706b\u5899\u4f2a\u88c5Referer\u5934\uff0c\u5982\uff1a\u201cReferer:XXXXXXX\u201d\u3002\n\nserver_names  \uff1a\u4e3a\u4e00\u4e2a\u6216\u591a\u4e2a\u670d\u52a1\u5668\u7684\u5217\u8868\uff0c0.5.33\u7248\u672c\u4ee5\u540e\u53ef\u4ee5\u5728\u540d\u79f0\u4e2d\u4f7f\u7528\u201c*\u201d\u901a\u914d\u7b26\u3002<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>10\u3001\u5185\u6838\u53c2\u6570\u4f18\u5316<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fs.file-max = 999999\uff1a\u8fd9\u4e2a\u53c2\u6570\u8868\u793a\u8fdb\u7a0b\uff08\u6bd4\u5982\u4e00\u4e2aworker\u8fdb\u7a0b\uff09\u53ef\u4ee5\u540c\u65f6\u6253\u5f00\u7684\u6700\u5927\u53e5\u67c4\u6570\uff0c\u8fd9\u4e2a\u53c2\u6570\u76f4\u7ebf\u9650\u5236\u6700\u5927\u5e76\u53d1\u8fde\u63a5\u6570\uff0c\u9700\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u914d\u7f6e\u3002\n\nnet.ipv4.tcp_max_tw_buckets = 6000 \uff1a\u8fd9\u4e2a\u53c2\u6570\u8868\u793a\u64cd\u4f5c\u7cfb\u7edf\u5141\u8bb8TIME_WAIT\u5957\u63a5\u5b57\u6570\u91cf\u7684\u6700\u5927\u503c\uff0c\u5982\u679c\u8d85\u8fc7\u8fd9\u4e2a\u6570\u5b57\uff0cTIME_WAIT\u5957\u63a5\u5b57\u5c06\u7acb\u523b\u88ab\u6e05\u9664\u5e76\u6253\u5370\u8b66\u544a\u4fe1\u606f\u3002\u8be5\u53c2\u6570\u9ed8\u8ba4\u4e3a180000\uff0c\u8fc7\u591a\u7684TIME_WAIT\u5957\u63a5\u5b57\u4f1a\u4f7fWeb\u670d\u52a1\u5668\u53d8\u6162\u3002\u6ce8\uff1a\u4e3b\u52a8\u5173\u95ed\u8fde\u63a5\u7684\u670d\u52a1\u7aef\u4f1a\u4ea7\u751fTIME_WAIT\u72b6\u6001\u7684\u8fde\u63a5\n\nnet.ipv4.ip_local_port_range = 1024 65000  \uff1a\u5141\u8bb8\u7cfb\u7edf\u6253\u5f00\u7684\u7aef\u53e3\u8303\u56f4\u3002\n\nnet.ipv4.tcp_tw_recycle = 1 \uff1a\u542f\u7528timewait\u5feb\u901f\u56de\u6536\u3002\n\nnet.ipv4.tcp_tw_reuse = 1 \uff1a\u5f00\u542f\u91cd\u7528\u3002\u5141\u8bb8\u5c06TIME-WAIT sockets\u91cd\u65b0\u7528\u4e8e\u65b0\u7684TCP\u8fde\u63a5\u3002\u8fd9\u5bf9\u4e8e\u670d\u52a1\u5668\u6765\u8bf4\u5f88\u6709\u610f\u4e49\uff0c\u56e0\u4e3a\u670d\u52a1\u5668\u4e0a\u603b\u4f1a\u6709\u5927\u91cfTIME-WAIT\u72b6\u6001\u7684\u8fde\u63a5\u3002\n\nnet.ipv4.tcp_keepalive_time = 30\uff1a\u8fd9\u4e2a\u53c2\u6570\u8868\u793a\u5f53keepalive\u542f\u7528\u65f6\uff0cTCP\u53d1\u9001keepalive\u6d88\u606f\u7684\u9891\u5ea6\u3002\u9ed8\u8ba4\u662f2\u5c0f\u65f6\uff0c\u82e5\u5c06\u5176\u8bbe\u7f6e\u7684\u5c0f\u4e00\u4e9b\uff0c\u53ef\u4ee5\u66f4\u5feb\u5730\u6e05\u7406\u65e0\u6548\u7684\u8fde\u63a5\u3002\n\nnet.ipv4.tcp_syncookies = 1 \uff1a\u5f00\u542fSYN Cookies\uff0c\u5f53\u51fa\u73b0SYN\u7b49\u5f85\u961f\u5217\u6ea2\u51fa\u65f6\uff0c\u542f\u7528cookies\u6765\u5904\u7406\u3002\n\nnet.core.somaxconn = 40960  \uff1aweb \u5e94\u7528\u4e2d listen \u51fd\u6570\u7684 backlog \u9ed8\u8ba4\u4f1a\u7ed9\u6211\u4eec\u5185\u6838\u53c2\u6570\u7684\u3002\n\nnet.core.somaxconn  \uff1a\u9650\u5236\u5230128\uff0c\u800cnginx\u5b9a\u4e49\u7684NGX_LISTEN_BACKLOG \u9ed8\u8ba4\u4e3a511\uff0c\u6240\u4ee5\u6709\u5fc5\u8981\u8c03\u6574\u8fd9\u4e2a\u503c\u3002\u6ce8\uff1a\u5bf9\u4e8e\u4e00\u4e2aTCP\u8fde\u63a5\uff0cServer\u4e0eClient\u9700\u8981\u901a\u8fc7\u4e09\u6b21\u63e1\u624b\u6765\u5efa\u7acb\u7f51\u7edc\u8fde\u63a5.\u5f53\u4e09\u6b21\u63e1\u624b\u6210\u529f\u540e,\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u7aef\u53e3\u7684\u72b6\u6001\u7531LISTEN\u8f6c\u53d8\u4e3aESTABLISHED,\u63a5\u7740\u8fd9\u6761\u94fe\u8def\u4e0a\u5c31\u53ef\u4ee5\u5f00\u59cb\u4f20\u9001\u6570\u636e\u4e86.\u6bcf\u4e00\u4e2a\u5904\u4e8e\u76d1\u542c(Listen)\u72b6\u6001\u7684\u7aef\u53e3,\u90fd\u6709\u81ea\u5df1\u7684\u76d1\u542c\u961f\u5217.\u76d1\u542c\u961f\u5217\u7684\u957f\u5ea6\u4e0e\u5982somaxconn\u53c2\u6570\u548c\u4f7f\u7528\u8be5\u7aef\u53e3\u7684\u7a0b\u5e8f\u4e2dlisten()\u51fd\u6570\u6709\u5173\u3002somaxconn\u5b9a\u4e49\u4e86\u7cfb\u7edf\u4e2d\u6bcf\u4e00\u4e2a\u7aef\u53e3\u6700\u5927\u7684\u76d1\u542c\u961f\u5217\u7684\u957f\u5ea6,\u8fd9\u662f\u4e2a\u5168\u5c40\u7684\u53c2\u6570,\u9ed8\u8ba4\u503c\u4e3a128\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u7ecf\u5e38\u5904\u7406\u65b0\u8fde\u63a5\u7684\u9ad8\u8d1f\u8f7d web\u670d\u52a1\u73af\u5883\u6765\u8bf4\uff0c\u9ed8\u8ba4\u7684 128 \u592a\u5c0f\u4e86\u3002\u5927\u591a\u6570\u73af\u5883\u8fd9\u4e2a\u503c\u5efa\u8bae\u589e\u52a0\u5230 1024 \u6216\u8005\u66f4\u591a\u3002\u5927\u7684\u4fa6\u542c\u961f\u5217\u5bf9\u9632\u6b62\u62d2\u7edd\u670d\u52a1 DoS \u653b\u51fb\u4e5f\u4f1a\u6709\u6240\u5e2e\u52a9\u3002\n\nnet.core.netdev_max_backlog = 262144  \uff1a\u6bcf\u4e2a\u7f51\u7edc\u63a5\u53e3\u63a5\u6536\u6570\u636e\u5305\u7684\u901f\u7387\u6bd4\u5185\u6838\u5904\u7406\u8fd9\u4e9b\u5305\u7684\u901f\u7387\u5feb\u65f6\uff0c\u5141\u8bb8\u9001\u5230\u961f\u5217\u7684\u6570\u636e\u5305\u7684\u6700\u5927\u6570\u76ee\u3002\n\nnet.ipv4.tcp_max_syn_backlog = 262144 \uff1a\u8fd9\u4e2a\u53c2\u6570\u6807\u793aTCP\u4e09\u6b21\u63e1\u624b\u5efa\u7acb\u9636\u6bb5\u63a5\u53d7SYN\u8bf7\u6c42\u961f\u5217\u7684\u6700\u5927\u957f\u5ea6\uff0c\u9ed8\u8ba4\u4e3a1024\uff0c\u5c06\u5176\u8bbe\u7f6e\u5f97\u5927\u4e00\u4e9b\u53ef\u4ee5\u4f7f\u51fa\u73b0Nginx\u7e41\u5fd9\u6765\u4e0d\u53caaccept\u65b0\u8fde\u63a5\u7684\u60c5\u51b5\u65f6\uff0cLinux\u4e0d\u81f3\u4e8e\u4e22\u5931\u5ba2\u6237\u7aef\u53d1\u8d77\u7684\u8fde\u63a5\u8bf7\u6c42\u3002\n\nnet.ipv4.tcp_rmem = 10240 87380 12582912 \uff1a\u8fd9\u4e2a\u53c2\u6570\u5b9a\u4e49\u4e86TCP\u63a5\u53d7\u7f13\u5b58\uff08\u7528\u4e8eTCP\u63a5\u53d7\u6ed1\u52a8\u7a97\u53e3\uff09\u7684\u6700\u5c0f\u503c\u3001\u9ed8\u8ba4\u503c\u3001\u6700\u5927\u503c\u3002\n\nnet.ipv4.tcp_wmem = 10240 87380 12582912\uff1a\u8fd9\u4e2a\u53c2\u6570\u5b9a\u4e49\u4e86TCP\u53d1\u9001\u7f13\u5b58\uff08\u7528\u4e8eTCP\u53d1\u9001\u6ed1\u52a8\u7a97\u53e3\uff09\u7684\u6700\u5c0f\u503c\u3001\u9ed8\u8ba4\u503c\u3001\u6700\u5927\u503c\u3002\n\nnet.core.rmem_default = 6291456\uff1a\u8fd9\u4e2a\u53c2\u6570\u8868\u793a\u5185\u6838\u5957\u63a5\u5b57\u63a5\u53d7\u7f13\u5b58\u533a\u9ed8\u8ba4\u7684\u5927\u5c0f\u3002\n\nnet.core.wmem_default = 6291456\uff1a\u8fd9\u4e2a\u53c2\u6570\u8868\u793a\u5185\u6838\u5957\u63a5\u5b57\u53d1\u9001\u7f13\u5b58\u533a\u9ed8\u8ba4\u7684\u5927\u5c0f\u3002\n\nnet.core.rmem_max = 12582912\uff1a\u8fd9\u4e2a\u53c2\u6570\u8868\u793a\u5185\u6838\u5957\u63a5\u5b57\u63a5\u53d7\u7f13\u5b58\u533a\u7684\u6700\u5927\u5927\u5c0f\u3002\n\nnet.core.wmem_max = 12582912\uff1a\u8fd9\u4e2a\u53c2\u6570\u8868\u793a\u5185\u6838\u5957\u63a5\u5b57\u53d1\u9001\u7f13\u5b58\u533a\u7684\u6700\u5927\u5927\u5c0f\u3002\n\nnet.ipv4.tcp_syncookies = 1\uff1a\u8be5\u53c2\u6570\u4e0e\u6027\u80fd\u65e0\u5173\uff0c\u7528\u4e8e\u89e3\u51b3TCP\u7684SYN\u653b\u51fb\u3002\n\n \n\n\u4e0b\u9762\u8d34\u4e00\u4e2a\u5b8c\u6574\u7684\u5185\u6838\u4f18\u5316\u8bbe\u7f6e\uff1a\n\nfs.file-max = 999999\nnet.ipv4.ip_forward = 0\nnet.ipv4.conf.default.rp_filter = 1\nnet.ipv4.conf.default.accept_source_route = 0\nkernel.sysrq = 0\nkernel.core_uses_pid = 1\nnet.ipv4.tcp_syncookies = 1\nkernel.msgmnb = 65536\nkernel.msgmax = 65536\nkernel.shmmax = 68719476736\nkernel.shmall = 4294967296\nnet.ipv4.tcp_max_tw_buckets = 6000\nnet.ipv4.tcp_sack = 1\nnet.ipv4.tcp_window_scaling = 1\nnet.ipv4.tcp_rmem = 10240 87380 12582912\nnet.ipv4.tcp_wmem = 10240 87380 12582912\nnet.core.wmem_default = 8388608\nnet.core.rmem_default = 8388608\nnet.core.rmem_max = 16777216\nnet.core.wmem_max = 16777216\nnet.core.netdev_max_backlog = 262144\nnet.core.somaxconn = 40960\nnet.ipv4.tcp_max_orphans = 3276800\nnet.ipv4.tcp_max_syn_backlog = 262144\nnet.ipv4.tcp_timestamps = 0\nnet.ipv4.tcp_synack_retries = 1\nnet.ipv4.tcp_syn_retries = 1\nnet.ipv4.tcp_tw_recycle = 1\nnet.ipv4.tcp_tw_reuse = 1\nnet.ipv4.tcp_mem = 94500000 915000000 927000000\nnet.ipv4.tcp_fin_timeout = 1\nnet.ipv4.tcp_keepalive_time = 30\nnet.ipv4.ip_local_port_range = 1024 65000\n\u6267\u884csysctl  -p\u4f7f\u5185\u6838\u4fee\u6539\u751f\u6548\u3002<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>11\u3001\u5173\u4e8e\u7cfb\u7edf\u8fde\u63a5\u6570\u7684\u4f18\u5316<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>linux \u9ed8\u8ba4\u503c open files\u4e3a1024\u3002\u67e5\u770b\u5f53\u524d\u7cfb\u7edf\u503c\uff1a\n\n# ulimit -n\n1024\n\u8bf4\u660eserver\u53ea\u5141\u8bb8\u540c\u65f6\u6253\u5f001024\u4e2a\u6587\u4ef6\u3002\n\n\u4f7f\u7528ulimit -a \u53ef\u4ee5\u67e5\u770b\u5f53\u524d\u7cfb\u7edf\u7684\u6240\u6709\u9650\u5236\u503c\uff0c\u4f7f\u7528ulimit -n \u53ef\u4ee5\u67e5\u770b\u5f53\u524d\u7684\u6700\u5927\u6253\u5f00\u6587\u4ef6\u6570\u3002\n\n\u65b0\u88c5\u7684linux \u9ed8\u8ba4\u53ea\u67091024 \uff0c\u5f53\u4f5c\u8d1f\u8f7d\u8f83\u5927\u7684\u670d\u52a1\u5668\u65f6\uff0c\u5f88\u5bb9\u6613\u9047\u5230error: too many open files\u3002\u56e0\u6b64\uff0c\u9700\u8981\u5c06\u5176\u6539\u5927\uff0c\u5728\/etc\/security\/limits.conf\u6700\u540e\u589e\u52a0\uff1a\n\n*               soft    nofile           65535\n*               hard   nofile           65535\n*               soft    noproc         65535\n*               hard   noproc         65535<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001Nginx\u8fd0\u884c\u5de5\u4f5c\u8fdb\u7a0b\u6570\u91cf\uff1a worker\u8fdb\u7a0b\u7684\u6570\u91cf\u4f1a\u76f4\u63a5\u5f71\u54cd\u6027\u80fd \uff0cNginx\u8fd0\u884c\u5de5\u4f5c\u8fdb\u7a0b\u4e2a\u6570\u4e00\u822c\u8bbe\u7f6eC&#8230;<\/p>\n","protected":false},"author":3,"featured_media":3444,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,22],"tags":[],"class_list":["post-3431","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-server"],"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/3431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=3431"}],"version-history":[{"count":6,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/3431\/revisions"}],"predecessor-version":[{"id":3450,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/3431\/revisions\/3450"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/3444"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=3431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=3431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=3431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}