{"id":3881,"date":"2021-05-20T12:02:23","date_gmt":"2021-05-20T04:02:23","guid":{"rendered":"http:\/\/blog.ywdevops.cn\/?p=3881"},"modified":"2026-09-20T16:44:06","modified_gmt":"2026-09-20T08:44:06","slug":"nginx-2","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2021\/05\/20\/nginx-2\/","title":{"rendered":"nginx\u7f16\u8bd1\u5b89\u88c5"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u751f\u4ea7\u73af\u5883\u4e2d\u4e00\u822c\u4e0d\u5efa\u8bae\u4f7f\u7528yum\u65b9\u6cd5\u6765\u5b89\u88c5nginx\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u9700\u8981\u901a\u8fc7\u7f16\u8bd1\u5b89\u88c5\u65b9\u5f0f\u6765\u5b89\u88c5\uff0c\u4e8c\u8fdb\u5236\u5305\u4e0b\u8f7d\u5730\u5740\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:\/\/nginx.org\/en\/download.html                 #\u4e8c\u8fdb\u5236\u5305\nhttps:\/\/nginx.org\/packages\/centos\/7\/x86_64\/RPMS\/  #rpm\u5305<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5148\u5b89\u88c5\u57fa\u7840\u7f16\u8bd1\u73af\u5883\uff0c\u6267\u884c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yum -y install gcc gcc-c++ autoconf automake make zlib* pcre*  #centos\napt update &amp;&amp; apt install build-essential  libpcre3 libpcre3-dev  openssl libssl-dev zlib1g-dev gcc  #ubuntu<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u9996\u5148\u5c06nginx\u5b89\u88c5\u5305\u4e0a\u4f20\u5230linux\u670d\u52a1\u5668\u4e0a\uff0c\u89e3\u538b\uff0c\u8fdb\u5165\u89e3\u538b\u540e\u7684\u76ee\u5f55\u4e2d\uff0c\u6267\u884c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"551\" height=\"112\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/2-6.png\" alt=\"\" class=\"wp-image-3882\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/2-6.png 551w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/2-6-300x61.png 300w\" sizes=\"auto, (max-width: 551px) 100vw, 551px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u56fe\u4e2d\u7684\u5b89\u88c5\u76ee\u5f55\u53ef\u4ee5\u6839\u636e\u9700\u8981\u81ea\u5b9a\u4e49\uff0c\u5982\u679c\u6dfb\u52a0\u6a21\u5757\uff0c\u53ef\u4ee5\u8fd9\u6837\uff1a.\/configure &#8211;prefix=\/usr\/local\/nginx &#8211;with-stream\uff0c\u8868\u793a\u7f16\u8bd1\u6a21\u5757stream(\u6b64\u6a21\u5757\u53ef\u4ee5\u4ee3\u7406tcp\u6216\u8005udp)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6dfb\u52a0\u591a\u4e2a\u529f\u80fd\u5305\u7684\u7f16\u8bd1\u5982\u4e0b(\u4e0b\u9762\u662f\u57fa\u4e8enginx1.26)\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/configure --prefix=\/usr\/local\/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_sub_module --with-http_addition_module --with-stream_ssl_module --with-stream --with-http_secure_link_module --with-http_gzip_static_module --with-threads --with-file-aio<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>--with-http_ssl_module<\/code><\/strong>\uff1a\u542f\u7528 HTTPS\/SSL \u652f\u6301\uff08\u5fc5\u5907\uff09<\/li>\n\n\n\n<li><strong><code>--with-http_v2_module<\/code><\/strong>\uff1a\u652f\u6301 HTTP\/2 \u534f\u8bae\uff0cnginx1.9.5\u7248\u672c\u540e\u624d\u652f\u6301<\/li>\n\n\n\n<li>\u200b<strong>\u200b<code>--with-http_realip_module<\/code><\/strong>\uff1a  \u83b7\u53d6\u5ba2\u6237\u7aef\u771f\u5b9e IP<\/li>\n\n\n\n<li><strong><code>--with-http_addition_module<\/code><\/strong>\uff1a\u54cd\u5e94\u5185\u5bb9\u8ffd\u52a0\u6587\u672c<\/li>\n\n\n\n<li><strong><code>--with-http_sub_module<\/code><\/strong>\uff1a\u54cd\u5e94\u5185\u5bb9\u66ff\u6362<\/li>\n\n\n\n<li><strong><code>--with-stream_ssl_module<\/code><\/strong>\uff1a\u52a0\u5bc6\u7684 TCP\/UDP \u4ee3\u7406\uff0c1.9.4\u7248\u672c\u540e\u652f\u6301<\/li>\n\n\n\n<li><strong><code>--with-stream<\/code><\/strong>\uff1aTCP\/UDP \u4ee3\u7406\u652f\u6301\uff08\u56db\u5c42\u8d1f\u8f7d\u5747\u8861\uff09\uff0c1.9.0\u7248\u672c\u540e\u652f\u6301<\/li>\n\n\n\n<li><strong><code>--with-http_secure_link_module<\/code><\/strong>\uff1a\u8d44\u6e90\u8bbf\u95ee\u6743\u9650\u63a7\u5236\uff08\u901a\u8fc7\u52a0\u5bc6\u94fe\u63a5\uff09<\/li>\n\n\n\n<li><strong><code>--with-http_gzip_static_module<\/code><\/strong>\uff1a\u9884\u538b\u7f29\u9759\u6001\u6587\u4ef6\uff08\u51cf\u5c11 CPU \u5f00\u9500\uff09<\/li>\n\n\n\n<li><strong><code>--with-threads<\/code><\/strong>\uff1a\u542f\u7528\u7ebf\u7a0b\u6c60\uff08\u63d0\u9ad8\u6027\u80fd\uff09<\/li>\n\n\n\n<li><strong><code>--with-file-aio<\/code><\/strong>\uff1a\u542f\u7528\u5f02\u6b65\u6587\u4ef6 I\/O\uff08\u63d0\u5347\u9ad8\u5e76\u53d1\u6027\u80fd\uff09<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u7f16\u8bd1\u5b8c\u6210\u540e\u6267\u884c\u547d\u4ee4make &amp;&amp; make install \u5b89\u88c5\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"550\" height=\"131\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/6-3.png\" alt=\"\" class=\"wp-image-3886\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/6-3.png 550w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/6-3-300x71.png 300w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u8fdb\u5165\/usr\/local\/nginx\/sbin\u76ee\u5f55\u6267\u884c\u547d\u4ee4.\/nginx\u542f\u52a8nginx ,\u6d4f\u89c8\u5668\u8bbf\u95ee\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"551\" height=\"224\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/7-4.png\" alt=\"\" class=\"wp-image-3887\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/7-4.png 551w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/7-4-300x122.png 300w\" sizes=\"auto, (max-width: 551px) 100vw, 551px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">4\u3001\u914d\u7f6e\u670d\u52a1\u81ea\u542f\u52a8\u6587\u4ef6\uff0c\u7f16\u8f91\u6587\u4ef6vim \/lib\/systemd\/system\/nginx.service\uff0c\u6dfb\u52a0\u5185\u5bb9\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"657\" height=\"270\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/8-2.png\" alt=\"\" class=\"wp-image-3888\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/8-2.png 657w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/8-2-300x123.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/8-2-600x247.png 600w\" sizes=\"auto, (max-width: 657px) 100vw, 657px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Unit]\nDescription=nginx\nDocumentation=http:\/\/nginx.org\/en\/docs\/\nAfter=network.target remote-fs.target nss-lookup.target\n\n\n&#91;Service]\nType=forking\n#ExecStartPre=\/usr\/local\/nginx\/sbin\/nginx -t -c \/usr\/local\/nginx\/conf\/nginx.conf\nExecStart=\/usr\/local\/nginx\/sbin\/nginx -c \/usr\/local\/nginx\/conf\/nginx.conf\nExecReload=\/usr\/local\/nginx\/sbin\/nginx -s reload\nExecStop=\/usr\/local\/nginx\/sbin\/nginx -s stop\n\n&#91;Install]\nWantedBy=multi-user.target\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u914d\u7f6e\u5b8c\u6210\u540e\u5373\u53ef\u901a\u8fc7\u670d\u52a1\u65b9\u5f0f\u542f\u52a8\u548c\u505c\u6b62nginx\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart nginx\nsystemctl status nginx\nsystemctl enable nginx\nsystemctl start nginx\nsystemctl stop nginx\nsystemctl relaod nginx<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5907\u6ce8\uff1a\u5982\u679c\u4fee\u6539\u4e86nginx\u914d\u7f6e\u6587\u4ef6\u540e\uff0c\u60f3\u67e5\u770b\u914d\u7f6e\u662f\u5426\u6b63\u786e\uff0c\u53ef\u6267\u884c\u547d\u4ee4nginx -t\u67e5\u770b\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"552\" height=\"124\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/10-2.png\" alt=\"\" class=\"wp-image-3892\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/10-2.png 552w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/05\/10-2-300x67.png 300w\" sizes=\"auto, (max-width: 552px) 100vw, 552px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u952e\u5b89\u88c5\u811a\u672c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n: '\n @function: \u5b89\u88c5nginx\uff0c\u672c\u4f8b\u5b50\u4e2d\u7248\u672c\u4e3anginx-1.21.6.tar.gz\n @author: gongguan\n @date: 2022-03-07\n'\necho \"&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;\u9996\u5148\u5b89\u88c5\u57fa\u7840\u7f16\u8bd1\u73af\u5883&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;\"\nyum -y install gcc gcc-c++ autoconf automake make pcre* zlib*\n&#91; $? -eq 0 ] &amp;&amp; echo \"&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;\u73af\u5883\u5b89\u88c5\u5b8c\u6210&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;\"\ntar -xf $(dirname $0)\/nginx-1.21.6.tar.gz\ncd nginx-1.21.6\n.\/configure --prefix=\/usr\/local\/nginx --with-stream --with-http_secure_link_module\n&#91; $? -eq 0 ] &amp;&amp; echo \"&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;\u7f16\u8bd1\u5b8c\u6210&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;\"\nmake &amp;&amp; make install\n&#91; $? -eq 0 ] &amp;&amp; echo \"&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;\u5b89\u88c5\u5b8c\u6210&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;\"\necho \"&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;\u6dfb\u52a0\u8f6f\u94fe\u63a5&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;\"\nln -s \/usr\/local\/nginx\/sbin\/nginx \/usr\/bin\/nginx\necho \"&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;\u7f16\u5199\u670d\u52a1\u5668\u6258\u7ba1\u6587\u4ef6&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;\"\ncat &gt; \/lib\/systemd\/system\/nginx.service &lt;&lt;EOF\n&#91;Unit]\nDescription=nginx\nDocumentation=http:\/\/nginx.org\/en\/docs\/\nAfter=network.target remote-fs.target nss-lookup.target\n\n\n&#91;Service]\nType=forking\n#ExecStartPre=\/usr\/local\/nginx\/sbin\/nginx -t -c \/usr\/local\/nginx\/conf\/nginx.conf\nExecStart=\/usr\/local\/nginx\/sbin\/nginx -c \/usr\/local\/nginx\/conf\/nginx.conf\nExecReload=\/usr\/local\/nginx\/sbin\/nginx -s reload\nExecStop=\/usr\/local\/nginx\/sbin\/nginx -s stop\n\n&#91;Install]\nWantedBy=multi-user.target\nEOF\necho \"\u6dfb\u52a0\u5f00\u673a\u81ea\u542f\u52a8\"\nsystemctl enable nginx\nsystemctl start nginx\nsystemctl status nginx\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&#8211;with-http_secure_link_module\uff1a\u7528\u4e8e\u914d\u7f6e\u9632\u76d7\u94fe<\/li>\n\n\n\n<li>&#8211;with-stream\uff1a\u7528\u4e8e\u4ee3\u7406TCP\u548cUDP<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f\uff1a\u5982\u679cnginx\u51fa\u73b0\u4e2d\u6587\u4e71\u7801\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u7f16\u7801\u4e3aUTF-8\uff0c\u5728nginx.conf\u914d\u7f6e\u4e2d\u6dfb\u52a0\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>charset utf-8;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u5728\u65e5\u5fd7\u4e2d\u8f93\u51fa\u83b7\u53d6\u7684\u771f\u5b9eIP\uff0c\u9700\u8981\u5728http\u5757\u4e2d\u6dfb\u52a0\u5982\u4e0b\u914d\u7f6e(\u9700\u8981http_realip_module\u6a21\u5757)\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u786e\u4fdd\u8bbe\u7f6e$http_x_forwarded_for\uff0c\u8be5\u53d8\u91cf\u7528\u4e8e\u8bb0\u5f55X-Forwarded-For\u7684\u503c\n  log_format  main  '$remote_addr- $remote_user &#91;$time_local] \"$request\" '\n                      '$status $body_bytes_sent \"$http_referer\" '\n                      '\"$http_user_agent\" \"$http_x_forwarded_for\"';<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-2-color\">\u9644\u52a0<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u751f\u4ea7\u73af\u5883\u4e0bnginx.conf\u914d\u7f6e\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>user nginx;\nworker_processes auto;\n\nerror_log \/var\/log\/nginx\/error.log warn;\npid \/run\/nginx.pid;\n\nevents {\n    worker_connections 4096;\n}\n\nhttp {\n    include \/etc\/nginx\/mime.types;\n    default_type application\/octet-stream;\n    #\u5b9a\u4e49\u65e5\u5fd7\u683c\u5f0f\n    log_format main\n        '$remote_addr - $host &#91;$time_local] '\n        '\"$request\" $status $body_bytes_sent '\n        'rt=$request_time '\n        'urt=$upstream_response_time';\n\n    access_log \/var\/log\/nginx\/access.log main;\n\n    sendfile on;\n    tcp_nopush on;\n    tcp_nodelay off;\n\n    keepalive_timeout 65;\n    keepalive_requests 100;\n    client_max_body_size 50m;\n    server_tokens off;\n\n    gzip on;\n    gzip_min_length 1k;\n    gzip_types\n        text\/plain\n        text\/css\n        application\/json\n        application\/javascript\n        application\/xml;\n\n    upstream app_backend {\n        server 127.0.0.1:8080;\n        server 127.0.0.1:8081;\n    }\n\n    server {\n        listen 80;\n        server_name example.com www.example.com;\n\n        location \/api\/ {\n            proxy_pass http:\/\/app_backend;\n\n            proxy_http_version 1.1;\n            proxy_set_header Host $host;\n            proxy_set_header X-Real-IP $remote_addr;\n            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n            proxy_set_header X-Forwarded-Proto $scheme;\n\n            proxy_connect_timeout 5s;\n            proxy_send_timeout 60s;\n            proxy_read_timeout 60s;\n\n            sendfile off;         #\u8986\u76d6\u5168\u5c40\n            tcp_nopush off;       #\u8986\u76d6\u5168\u5c40\u914d\u7f6e\n            tcp_nodelay on;       #\u8986\u76d6\u5168\u5c40\n            proxy_tcp_nodelay on;\n        }\n\n        location \/static\/ {\n            alias \/var\/www\/static\/;\n            expires 7d;\n            access_log off;\n            #\u9759\u6001\u8d44\u6e90\u914d\u7f6e\u91cc\u5df2\u7ecf\u9ed8\u8ba4\u4f7f\u7528http{}\u4e2d\u7684sendfile \u548c tcp_nopush\u914d\u7f6e\n        }\n\n        error_page 404 \/404.html;\n        error_page 500 502 503 504 \/50x.html;\n    }\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-2-color\">user nginx;<\/mark><\/strong>  #master\u8fdb\u7a0b\u662froot\u542f\u52a8\uff0cworker\u8fdb\u7a0b\u662fnginx\u7528\u6237\u542f\u52a8\uff0c\u5982\u679cnginx\u7684\u7aef\u53e3\u57281-1023\uff0c\u5fc5\u987b\u4f7f\u7528root\u7528\u6237\u542f\u52a8\uff0c\u5426\u5219\u4e0d\u8981\u6c42\u5fc5\u987broot\uff0c\u4e0d\u5efa\u8bae\u8bbe\u7f6euser root;<\/li>\n\n\n\n<li><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-2-color\">worker_processes auto;<\/mark><\/strong>  #\u6307\u5b9aworker\u8fdb\u7a0b\u6570\u91cf\uff0c\u914d\u7f6e\u4e3aauto\u540e\u4f1a\u6839\u636eCPU\u6838\u5fc3\u6570\u81ea\u52a8\u8bbe\u7f6e<\/li>\n\n\n\n<li><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-2-color\">worker_connections 4096;<\/mark><\/strong>  #\u6bcf\u4e2a worker \u8fdb\u7a0b\u5141\u8bb8\u7684\u6700\u5927\u8fde\u63a5\u6570\uff0c\u7406\u8bba\u4e0a\u6700\u5927\u8fde\u63a5\u6570\u4e3a\uff1aworker_processes \u00d7 worker_connections<\/li>\n\n\n\n<li><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-2-color\">sendfile on; <\/mark><\/strong># \u542f\u7528\u9ad8\u6548\u6587\u4ef6\u4f20\u8f93\u673a\u5236\uff0c\u51cf\u5c11\u6587\u4ef6\u5728\u7528\u6237\u6001\u548c\u5185\u6838\u6001\u4e4b\u95f4\u7684\u590d\u5236\uff0c\u53ea\u80fd\u5904\u7406\u9759\u6001\u6587\u4ef6\uff0c\u6bd4\u5982\u672c\u5730\u7684\u6587\u4ef6\uff0c\u4e0d\u80fd\u5904\u7406proxy_pass\u8c03\u7528\u7684\u540e\u7aef\u670d\u52a1\uff0c\u56e0\u4e3a\u540e\u7aef\u662f\u52a8\u6001\u7684\uff0csendfile\u4f1a\u76f4\u63a5\u5931\u6548<\/li>\n\n\n\n<li><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-2-color\">tcp_nopush on;<\/mark><\/strong> #\u914d\u5408 <code>sendfile<\/code> \u4f7f\u7528\uff0c\u5c3d\u91cf\u5c06\u54cd\u5e94\u5934\u548c\u6587\u4ef6\u6570\u636e\u4e00\u6b21\u6027\u53d1\u9001\uff0c\u63d0\u9ad8\u7f51\u7edc\u4f20\u8f93\u6548\u7387<\/li>\n\n\n\n<li><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-2-color\">tcp_nodelay on;<\/mark><\/strong> #\u6709\u6570\u636e\u9a6c\u4e0a\u53d1\uff0c\u964d\u4f4e\u5ef6\u8fdf\u53d1\u9001\uff0c\u9002\u5408\u9700\u8981\u4f4e\u5ef6\u8fdf\u54cd\u5e94\u7684\u573a\u666f\uff0c\u901a\u5e38\u5728\u957f\u8fde\u63a5\u542f\u7528\u65f6\u6bd4\u8f83\u5e38\u89c1\uff0c\u6bd4\u5982\u8c03\u7528websocket\uff0c\u8c03\u7528\u540e\u7aef\/api\u670d\u52a1\uff0ctcp_nodelay \u4e00\u822c\u76f4\u63a5\u914d\u7f6e\u5728proxy_pass\u8c03\u7528\u7684\u540e\u7aef\u670d\u52a1\u91cc\u5c31\u884c\u4e86<\/li>\n\n\n\n<li><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-2-color\">proxy_tcp_nodelay on;<\/mark><\/strong> # tcp_nodelay on\u7528\u4e8e\u63a7\u5236 <strong>\u5ba2\u6237\u7aef &lt;==> Nginx<\/strong> \u7684\u8fde\u63a5\uff0cproxy_tcp_nodelay on \u4e13\u95e8\u63a7\u5236 <strong>Nginx &lt;==> \u540e\u7aef\u4e0a\u6e38\u670d\u52a1<\/strong> \u7684 TCP \u8fde\u63a5\uff0c\u548ctcp_nodelay on \u914d\u5408\u4f7f\u7528<\/li>\n\n\n\n<li><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-2-color\">keepalive_timeout 65;<\/mark><\/strong> #\u8bbe\u7f6e HTTP \u957f\u8fde\u63a5\u7684\u8d85\u65f6\u65f6\u95f4\uff0c\u5355\u4f4d\u4e3a\u79d2\uff0c\u5ba2\u6237\u7aef\u5728\u8fd9\u6bb5\u65f6\u95f4\u5185\u6ca1\u6709\u65b0\u8bf7\u6c42\uff0c\u8fde\u63a5\u53ef\u80fd\u4f1a\u88ab\u5173\u95ed\uff0c\u518d\u6b21\u8bf7\u6c42\u7684\u65f6\u5019\u53c8\u8981\u91cd\u65b0\u5efa\u7acbTCP\u8fde\u63a5\uff0c\u4e0d\u4f1a\u590d\u7528\u4e4b\u524d\u7684\uff0c\u5982\u679c\u572865s\u5185\u518d\u6b21\u53d1\u8bf7\u6c42\uff0c\u90a3\u5c31\u590d\u7528\u4e4b\u524d\u5efa\u7acb\u7684TCP\u8fde\u63a5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u6548\u7387\uff0ckeepalive_timeout \u53ea\u9488\u5bf9\u666e\u901a HTTP\/HTTPS\uff0c\u5bf9WebSocket\u65e0\u6548\uff0cWebSocket \u662f\u5347\u7ea7\u540e\u7684\u957f\u8fde\u63a5\uff0c\u4e0d\u8d70 http keep\u2011alive \u903b\u8f91\uff0c\u5b83\u7684\u8d85\u65f6\u770bproxy_read_timeout 300s;<\/li>\n\n\n\n<li><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-2-color\">keepalive_requests 100;<\/mark><\/strong> #\u540c\u4e00\u6761\u957f\u8fde\u63a5\u4e0a\u9762\uff0c\u6700\u591a\u5904\u7406 100 \u6b21 http \u8bf7\u6c42\uff0c\u4e0d\u7ba1\u65f6\u95f4\u5230\u6ca1\u5230\uff0c\u5230\u8fbe\u6570\u91cf\u76f4\u63a5\u5173\u95ed\u8fde\u63a5\uff0c\u9632\u6b62\u67d0\u4e00\u4e2a\u5ba2\u6237\u7aef\u65e0\u9650\u590d\u7528\u4e00\u6761\u8fde\u63a5\uff0c\u505a\u4e00\u4e9b\u6076\u610f\u884c\u4e3a<\/li>\n\n\n\n<li><code><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-2-color\">client_max_body_size<\/mark><\/strong><\/code> #\u9650\u5236\u5ba2\u6237\u7aef\u8bf7\u6c42\u4f53\u7684\u6700\u5927\u5927\u5c0f\uff0c\u5e38\u7528\u4e8e\u9650\u5236\u6587\u4ef6\u4e0a\u4f20\u5927\u5c0f<\/li>\n\n\n\n<li><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-2-color\">server_tokens off;<\/mark><\/strong> #\u662f\u5426\u5728\u9519\u8bef\u9875\u9762\u548c\u54cd\u5e94\u5934\u4e2d\u663e\u793a Nginx \u7248\u672c\u53f7\uff0c\u5efa\u8bae\u5173\u95ed\uff0c\u53ef\u4ee5\u51cf\u5c11\u66b4\u9732\u670d\u52a1\u7248\u672c\u4fe1\u606f<\/li>\n\n\n\n<li><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-2-color\">proxy_set_header X-Forwarded-Proto $scheme;<\/mark><\/strong> #\u539f\u59cb\u5ba2\u6237\u7aef\u8bbf\u95ee\u4f7f\u7528\u7684\u534f\u8bae\uff08http \/https\uff09\u4f20\u9012\u7ed9\u540e\u7aef\u5e94\u7528\u670d\u52a1\uff0c\u5982\u679c\u7528\u6237\u901a\u8fc7HTTP\u8bbf\u95ee $scheme\u5c31\u662fhttp\u5426\u5219\u5c31\u662fhttps\uff0c\u540e\u7aef\u53ef\u6839\u636e\u8fd9\u4e2a\u534f\u8bae\u505a\u62fc\u63a5URL\u6216\u8005\u5224\u65ad\u662f\u5426\u662f\u5b89\u5168\u94fe\u63a5\uff0c\u8fdb\u884c\u5177\u4f53\u7684\u4e1a\u52a1\u903b\u8f91<\/li>\n\n\n\n<li><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-2-color\">proxy_set_header Host $host;<\/mark><\/strong> #\u628a<strong>\u6d4f\u89c8\u5668\u5b9e\u9645\u8bbf\u95ee\u7684\u57df\u540d<\/strong>\uff0c\u901a\u8fc7\u8bf7\u6c42\u5934<code>Host<\/code>\u4f20\u9012\u7ed9\u540e\u7aef\u670d\u52a1\uff0c\u5982\u679c\u4e0d\u914d\u7f6e\u8fd9\u4e2a\uff0c\u53d1\u9001\u7ed9\u540e\u7aef\u7684HTTP \u5934\u90e8\u5730\u5740\u5c31\u662f127.0.0.1:8080\uff0c\u540e\u7aef\u5982\u679c\u6709\u591a\u57df\u540d\u670d\u52a1\uff0c\u5c31\u4f1a\u627e\u4e0d\u5230\u57df\u540d\uff0c\u6216\u8005\u56de\u8c03\u5730\u5740\u62fc\u63a5\u3001\u5176\u4ed6\u5730\u5740\u62fc\u63a5\u7684\u65f6\u5019\u5c31\u4f1a\u51fa\u5dee\u9519\uff0c\u5bfc\u81f4404<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u751f\u4ea7\u73af\u5883\u4e2d\u4e00\u822c\u4e0d\u5efa\u8bae\u4f7f\u7528yum\u65b9\u6cd5\u6765\u5b89\u88c5nginx\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u9700\u8981\u901a\u8fc7\u7f16\u8bd1\u5b89\u88c5\u65b9\u5f0f\u6765\u5b89\u88c5\uff0c\u4e8c\u8fdb\u5236\u5305\u4e0b\u8f7d\u5730\u5740\uff1a  [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":3891,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,22],"tags":[],"class_list":["post-3881","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-server"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/3881","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=3881"}],"version-history":[{"count":40,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/3881\/revisions"}],"predecessor-version":[{"id":21260,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/3881\/revisions\/21260"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/3891"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=3881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=3881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=3881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}