{"id":86989,"date":"2026-07-29T15:56:31","date_gmt":"2026-07-29T07:56:31","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/86989.html"},"modified":"2026-07-29T15:56:31","modified_gmt":"2026-07-29T07:56:31","slug":"%e4%b8%8a%e7%ab%a0%e8%8a%82%e4%b8%ad%e6%96%87%e4%bb%b6%e7%9a%84%e8%ae%b2%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/86989.html","title":{"rendered":"\u4e0a\u7ae0\u8282\u4e2d\u6587\u4ef6\u7684\u8bb2\u89e3"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6-toc\" style=\"margin-left:0px\">\u914d\u7f6e\u6587\u4ef6<\/p>\n<p id=\"1%E3%80%81nginx.conf-toc\" style=\"margin-left:40px\">1\u3001nginx.conf<\/p>\n<p id=\"2%E3%80%81lab.conf%EF%BC%9A%E5%AE%9A%E4%B9%89%E5%90%8E%E7%AB%AF%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%BB%84-toc\" style=\"margin-left:40px\">2\u3001lab.conf&#xff1a;\u5b9a\u4e49\u540e\u7aef\u670d\u52a1\u5668\u7ec4<\/p>\n<hr \/>\n<h2 id=\"%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6\">\u914d\u7f6e\u6587\u4ef6<\/h2>\n<p>\u4e24\u4e2a\u914d\u7f6e\u6587\u4ef6\u7684\u5173\u7cfb\u53ef\u4ee5\u628a\u5b83\u4eec\u7406\u89e3\u6210&#xff1a;<\/p>\n<ul>\n<li>nginx.conf&#xff1a;\u516c\u53f8\u7684\u201c\u603b\u89c4\u7ae0\u5236\u5ea6\u201d<\/li>\n<li>lab.conf&#xff1a;\u67d0\u4e2a\u5177\u4f53\u7f51\u7ad9\u7684\u201c\u5de5\u4f5c\u89c4\u5219\u201d<\/li>\n<\/ul>\n<p>\u52a0\u8f7d\u5173\u7cfb&#xff1a;<\/p>\n<p>nginx.conf \u2514\u2500\u2500 http \u00a0 \u00a0 \u2514\u2500\u2500 include \/etc\/nginx\/conf.d\/*.conf \u00a0 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500 lab.conf \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u251c\u2500\u2500 upstream \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500 server \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500 location<\/p>\n<p>nginx.conf\u00a0\u6700\u540e\u4e00\u884c\u52a0\u8f7d\u4e86\u00a0conf.d\u00a0\u76ee\u5f55\u4e2d\u7684\u914d\u7f6e&#xff0c;\u6240\u4ee5\u00a0lab.conf\u00a0\u5b9e\u9645\u4e0a\u4f1a\u88ab\u63d2\u5165\u00a0http\u00a0\u5757\u5185\u3002<\/p>\n<h3 id=\"1%E3%80%81nginx.conf\">1\u3001nginx.conf<\/h3>\n<h4 id=\"%EF%BC%881%EF%BC%89%E8%AF%A6%E8%A7%A3\">&#xff08;1&#xff09;\u8be6\u89e3<\/h4>\n<p>\u6587\u4ef6\u4f4d\u7f6e&#xff1a;conf\/nginx.conf<\/p>\n<h5 id=\"%E2%91%A0%20Worker%20%E8%BF%9B%E7%A8%8B%E6%95%B0%E9%87%8F\">\u2460 Worker \u8fdb\u7a0b\u6570\u91cf<\/h5>\n<p>worker_processes auto; <\/p>\n<p>Nginx \u901a\u5e38\u6709\u4e24\u7c7b\u8fdb\u7a0b&#xff1a;<\/p>\n<p>Master \u4e3b\u8fdb\u7a0b \u251c\u2500\u2500 Worker 1 \u251c\u2500\u2500 Worker 2 \u251c\u2500\u2500 Worker 3 \u2514\u2500\u2500 Worker 4<\/p>\n<p>a. Master \u8fdb\u7a0b<\/p>\n<p>\u8d1f\u8d23&#xff1a;<\/p>\n<ul>\n<li>\u8bfb\u53d6\u914d\u7f6e<\/li>\n<li>\u521b\u5efa Worker<\/li>\n<li>\u63a5\u6536 reload\/stop \u4fe1\u53f7<\/li>\n<li>\u5e73\u6ed1\u66f4\u65b0\u914d\u7f6e<\/li>\n<\/ul>\n<p>b. Worker \u8fdb\u7a0b<\/p>\n<p>\u8d1f\u8d23&#xff1a;<\/p>\n<ul>\n<li>\u63a5\u6536\u8bf7\u6c42<\/li>\n<li>\u8fd4\u56de\u9759\u6001\u6587\u4ef6<\/li>\n<li>\u8f6c\u53d1\u8bf7\u6c42<\/li>\n<li>\u5199\u65e5\u5fd7<\/li>\n<\/ul>\n<p>auto\u00a0\u8868\u793a\u8ba9 Nginx \u6839\u636e CPU \u6570\u91cf\u81ea\u52a8\u51b3\u5b9a Worker \u6570\u91cf\u3002<\/p>\n<p>\u5728\u00a0WSL \u4e2d&#xff0c;\u53ef\u4ee5\u67e5\u770b&#xff1a;podman exec nginx-lab ps<\/p>\n<h5 id=\"%E2%91%A1%20%E9%94%99%E8%AF%AF%E6%97%A5%E5%BF%97\">\u2461 \u9519\u8bef\u65e5\u5fd7<\/h5>\n<p>error_log \/var\/log\/nginx\/error.log warn; <\/p>\n<p>\u542b\u4e49\u662f&#xff1a;<\/p>\n<ul>\n<li>\u9519\u8bef\u65e5\u5fd7\u8def\u5f84&#xff1a;\/var\/log\/nginx\/error.log<\/li>\n<li>\u65e5\u5fd7\u7ea7\u522b&#xff1a;warn<\/li>\n<\/ul>\n<p>\u5e38\u89c1\u65e5\u5fd7\u7ea7\u522b\u7531\u8be6\u7ec6\u5230\u4e25\u91cd&#xff0c;\u5927\u81f4\u4e3a&#xff1a;<\/p>\n<p>debug \u2192 info \u2192 notice \u2192 warn \u2192 error \u2192 crit \u2192 alert \u2192 emerg<\/p>\n<p>\u4f7f\u7528\u00a0warn\u00a0\u65f6&#xff0c;\u4f1a\u8bb0\u5f55\u8b66\u544a\u4ee5\u53ca\u66f4\u4e25\u91cd\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<ul>\n<li>\u540e\u7aef\u8fde\u63a5\u5931\u8d25<\/li>\n<li>\u540e\u7aef\u54cd\u5e94\u8d85\u65f6<\/li>\n<li>\u8bf7\u6c42\u88ab\u9650\u6d41<\/li>\n<li>\u6587\u4ef6\u4e0d\u5b58\u5728<\/li>\n<li>\u914d\u7f6e\u6216\u8fd0\u884c\u5f02\u5e38<\/li>\n<\/ul>\n<p>\u9879\u76ee\u628a\u5bb9\u5668\u91cc\u7684\u65e5\u5fd7\u76ee\u5f55\u6620\u5c04\u5230\u4e86\u672c\u673a&#xff1a;<\/p>\n<ul>\n<li>\u5bb9\u5668&#xff1a;\/var\/log\/nginx\/<\/li>\n<li>\u672c\u673a&#xff1a;~\/nginx-podman-lab\/logs\/<\/li>\n<\/ul>\n<p>\u6240\u4ee5\u53ef\u4ee5\u76f4\u63a5\u67e5\u770b&#xff1a;tail -f ~\/nginx-podman-lab\/logs\/error.log<\/p>\n<h5 id=\"%E2%91%A2%20PID%20%E6%96%87%E4%BB%B6\">\u2462 PID \u6587\u4ef6<\/h5>\n<p>pid \/var\/run\/nginx.pid; <\/p>\n<p>PID \u662f\u8fdb\u7a0b\u7f16\u53f7\u3002<\/p>\n<p>Nginx \u628a Master \u8fdb\u7a0b\u7f16\u53f7\u5199\u5230\u8fd9\u4e2a\u6587\u4ef6\u4e2d&#xff0c;\u4f8b\u5982&#xff1a;26<\/p>\n<p>\u5f53\u6267\u884c&#xff1a;nginx -s reload<\/p>\n<p>Nginx \u4f1a\u901a\u8fc7 PID \u627e\u5230 Master \u8fdb\u7a0b&#xff0c;\u7136\u540e\u5411\u5b83\u53d1\u9001\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u7684\u4fe1\u53f7\u3002<\/p>\n<p>\u4e00\u822c\u4e0d\u9700\u8981\u624b\u52a8\u4fee\u6539\u8fd9\u4e00\u9879\u3002<\/p>\n<h5 id=\"%E2%91%A3%C2%A0events%C2%A0%E5%9D%97\">\u2463\u00a0events\u00a0\u5757<\/h5>\n<p>events {<br \/>\n    worker_connections 1024;<br \/>\n    multi_accept on;<br \/>\n} <\/p>\n<p>\u8fd9\u91cc\u7ba1\u7406\u7f51\u7edc\u8fde\u63a5\u3002<\/p>\n<p>a. worker_connections 1024<\/p>\n<p>\u8868\u793a\u6bcf\u4e2a Worker \u6700\u591a\u53ef\u4ee5\u540c\u65f6\u6253\u5f00\u5927\u7ea6 1024 \u4e2a\u8fde\u63a5\u3002<\/p>\n<p>\u5047\u8bbe\u6709 4 \u4e2a Worker&#xff0c;\u7406\u8bba\u8fde\u63a5\u4e0a\u9650\u5927\u81f4\u4e3a&#xff1a;<\/p>\n<p>4 \u00d7 1024 &#061; 4096<\/p>\n<p>\u4f46\u4e0d\u80fd\u7b80\u5355\u5730\u5c06\u5b83\u5f53\u6210\u201c\u6700\u591a 4096 \u4e2a\u7528\u6237\u201d&#xff0c;\u56e0\u4e3a\u4e00\u6b21\u53cd\u5411\u4ee3\u7406\u901a\u5e38\u6d89\u53ca\u4e24\u4e2a\u8fde\u63a5&#xff1a;<\/p>\n<p>\u7528\u6237 \u2190\u8fde\u63a51\u2192 Nginx \u2190\u8fde\u63a52\u2192 \u540e\u7aef<\/p>\n<p>\u5b9e\u9645\u5bb9\u91cf\u8fd8\u4f1a\u53d7\u5230\u4ee5\u4e0b\u56e0\u7d20\u9650\u5236&#xff1a;<\/p>\n<ul>\n<li>Linux \u6587\u4ef6\u63cf\u8ff0\u7b26\u4e0a\u9650<\/li>\n<li>CPU<\/li>\n<li>\u5185\u5b58<\/li>\n<li>\u540e\u7aef\u5904\u7406\u80fd\u529b<\/li>\n<li>\u957f\u8fde\u63a5\u6570\u91cf<\/li>\n<\/ul>\n<p>\u672c\u5b9e\u9a8c\u4e2d\u7684 1024 \u8db3\u591f\u4f7f\u7528\u3002<\/p>\n<p>b. multi_accept on<\/p>\n<p>\u5f53\u6709\u5f88\u591a\u65b0\u8fde\u63a5\u540c\u65f6\u5230\u6765\u65f6&#xff0c;\u5141\u8bb8 Worker \u4e00\u6b21\u63a5\u53d7\u591a\u4e2a\u8fde\u63a5\u3002<\/p>\n<p>\u5927\u767d\u8bdd&#xff1a;<\/p>\n<p>\u95e8\u53e3\u540c\u65f6\u6765\u4e86\u5f88\u591a\u987e\u5ba2&#xff0c;\u63a5\u5f85\u5458\u53ef\u4ee5\u8fde\u7eed\u63a5\u5f85&#xff0c;\u4e0d\u5fc5\u6bcf\u6b21\u53ea\u9886\u4e00\u4e2a\u4eba\u3002<\/p>\n<p>\u751f\u4ea7\u73af\u5883\u4e2d\u662f\u5426\u5f00\u542f\u9700\u8981\u7ed3\u5408\u8d1f\u8f7d\u6d4b\u8bd5&#xff0c;\u672c\u5b9e\u9a8c\u4e3b\u8981\u7528\u4e8e\u5c55\u793a\u3002<\/p>\n<h4 id=\"%EF%BC%882%EF%BC%89http%C2%A0%E5%9D%97%E8%AF%A6%E7%BB%86%E8%AE%B2%E8%A7%A3\">&#xff08;2&#xff09;http\u00a0\u5757\u8be6\u7ec6\u8bb2\u89e3<\/h4>\n<p>http {<br \/>\n    &#8230;<br \/>\n} <\/p>\n<p>\u6240\u6709\u666e\u901a HTTP\/HTTPS \u7f51\u7ad9\u914d\u7f6e\u901a\u5e38\u90fd\u653e\u5728\u8fd9\u91cc\u3002<\/p>\n<h5 id=\"%E2%91%A0%20%E6%96%87%E4%BB%B6%E7%B1%BB%E5%9E%8B%E8%A1%A8\">\u2460 \u6587\u4ef6\u7c7b\u578b\u8868<\/h5>\n<p>include \/etc\/nginx\/mime.types;<\/p>\n<p>default_type application\/octet-stream; <\/p>\n<p>a. mime.types<\/p>\n<p>\u5b83\u544a\u8bc9\u6d4f\u89c8\u5668\u4e0d\u540c\u6587\u4ef6\u662f\u4ec0\u4e48\u7c7b\u578b&#xff1a;<\/p>\n<p>.html \u2192 text\/html<\/p>\n<p>.css \u2192 text\/css<\/p>\n<p>.js \u2192 application\/javascript<\/p>\n<p>.png \u2192 image\/png<\/p>\n<p>\u5982\u679c\u6ca1\u6709\u6b63\u786e\u7c7b\u578b&#xff0c;\u6d4f\u89c8\u5668\u53ef\u80fd\u65e0\u6cd5\u6b63\u5e38\u89e3\u6790\u6587\u4ef6\u3002<\/p>\n<p>b. default_type<\/p>\n<p>\u5982\u679c Nginx \u4e0d\u8ba4\u8bc6\u67d0\u4e2a\u6587\u4ef6\u6269\u5c55\u540d&#xff0c;\u5c31\u4f7f\u7528&#xff1a;application\/octet-stream<\/p>\n<p>\u5b83\u8868\u793a&#xff1a;<\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u666e\u901a\u4e8c\u8fdb\u5236\u6587\u4ef6&#xff0c;\u5177\u4f53\u7c7b\u578b\u4e0d\u786e\u5b9a\u3002<\/p>\n<h5 id=\"%E2%91%A1%20%E9%9A%90%E8%97%8F%20Nginx%20%E7%89%88%E6%9C%AC\">\u2461 \u9690\u85cf Nginx \u7248\u672c<\/h5>\n<p>server_tokens off; <\/p>\n<p>\u9ed8\u8ba4\u9519\u8bef\u9875\u9762\u6216\u54cd\u5e94\u5934\u53ef\u80fd\u663e\u793a&#xff1a;nginx\/1.27.5<\/p>\n<p>\u5173\u95ed\u540e\u901a\u5e38\u53ea\u663e\u793a&#xff1a;nginx<\/p>\n<p>\u8fd9\u6837\u53ef\u4ee5\u51cf\u5c11\u7248\u672c\u4fe1\u606f\u66b4\u9732\u3002<\/p>\n<p>\u4f46\u5b83\u53ea\u662f\u57fa\u7840\u5b89\u5168\u8bbe\u7f6e&#xff0c;\u4e0d\u4ee3\u8868\u670d\u52a1\u5668\u56e0\u6b64\u5c31\u7edd\u5bf9\u5b89\u5168\u3002<\/p>\n<h5 id=\"%E2%91%A2%20%E9%AB%98%E6%95%88%E5%8F%91%E9%80%81%E6%96%87%E4%BB%B6\">\u2462 \u9ad8\u6548\u53d1\u9001\u6587\u4ef6<\/h5>\n<p>sendfile on;<\/p>\n<p>tcp_nopush on; <\/p>\n<p>a. sendfile on<\/p>\n<p>\u666e\u901a\u53d1\u9001\u6587\u4ef6\u8fc7\u7a0b\u53ef\u80fd\u662f&#xff1a;\u78c1\u76d8 \u2192 \u7a0b\u5e8f\u5185\u5b58 \u2192 \u7f51\u7edc<\/p>\n<p>\u5f00\u542f\u00a0sendfile\u00a0\u540e&#xff0c;Linux \u53ef\u4ee5\u66f4\u9ad8\u6548\u5730\u628a\u6587\u4ef6\u6570\u636e\u4ea4\u7ed9\u7f51\u7edc\u5c42&#xff0c;\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u6570\u636e\u590d\u5236\u3002<\/p>\n<p>\u9002\u5408&#xff1a;<\/p>\n<ul>\n<li>HTML<\/li>\n<li>CSS<\/li>\n<li>JavaScript<\/li>\n<li>\u56fe\u7247<\/li>\n<li>\u4e0b\u8f7d\u6587\u4ef6<\/li>\n<\/ul>\n<p>b. tcp_nopush on<\/p>\n<p>\u914d\u5408\u00a0sendfile\u00a0\u4f7f\u7528&#xff0c;\u5c3d\u91cf\u628a\u6570\u636e\u51d1\u6210\u8f83\u5b8c\u6574\u7684\u6570\u636e\u5305\u540e\u518d\u53d1\u9001\u3002<\/p>\n<p>\u5927\u767d\u8bdd&#xff1a;<\/p>\n<p>\u9001\u8d27\u65f6\u5c3d\u91cf\u88c5\u6ee1\u4e00\u8f66\u518d\u53d1&#xff0c;\u800c\u4e0d\u662f\u4e00\u4e2a\u5c0f\u5305\u88f9\u5c31\u53d1\u4e00\u8f86\u8f66\u3002<\/p>\n<h5 id=\"%E2%91%A3%20%E5%AE%A2%E6%88%B7%E7%AB%AF%E9%95%BF%E8%BF%9E%E6%8E%A5\">\u2463 \u5ba2\u6237\u7aef\u957f\u8fde\u63a5<\/h5>\n<p>keepalive_timeout 65; <\/p>\n<p>\u6d4f\u89c8\u5668\u8bbf\u95ee\u7f51\u9875\u65f6&#xff0c;\u901a\u5e38\u9700\u8981\u8bf7\u6c42\u591a\u4e2a\u6587\u4ef6&#xff1a;<\/p>\n<p>index.html<\/p>\n<p>style.css<\/p>\n<p>app.js<\/p>\n<p>\u56fe\u7247<\/p>\n<p>\u5982\u679c\u6ca1\u6709\u957f\u8fde\u63a5&#xff0c;\u6bcf\u4e2a\u6587\u4ef6\u53ef\u80fd\u90fd\u9700\u8981\u91cd\u65b0\u5efa\u7acb TCP \u8fde\u63a5\u3002<\/p>\n<p>\u5f00\u542f Keepalive \u540e&#xff1a;<\/p>\n<p>\u5efa\u7acb\u4e00\u6b21\u8fde\u63a5<\/p>\n<p>\u251c\u2500\u2500 \u8bf7\u6c42 index.html<\/p>\n<p>\u251c\u2500\u2500 \u8bf7\u6c42 style.css<\/p>\n<p>\u251c\u2500\u2500 \u8bf7\u6c42 app.js<\/p>\n<p>\u2514\u2500\u2500 \u6682\u65f6\u4fdd\u7559\u8fde\u63a5<\/p>\n<p>65\u00a0\u8868\u793a\u8fde\u63a5\u7a7a\u95f2\u7ea6 65 \u79d2\u540e\u5173\u95ed\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a;\u8fd9\u662f\u5ba2\u6237\u7aef\u5230 Nginx\u00a0\u7684\u957f\u8fde\u63a5\u8bbe\u7f6e&#xff0c;\u4e0d\u662f Nginx \u5230\u540e\u7aef\u7684\u8fde\u63a5\u6c60\u3002<\/p>\n<h5 id=\"%E2%91%A4%20%E4%B8%8A%E4%BC%A0%E5%A4%A7%E5%B0%8F%E9%99%90%E5%88%B6\">\u2464 \u4e0a\u4f20\u5927\u5c0f\u9650\u5236<\/h5>\n<p>client_max_body_size 10m; <\/p>\n<p>\u5ba2\u6237\u7aef\u8bf7\u6c42\u4f53\u6700\u5927\u4e3a 10MB\u3002<\/p>\n<p>\u4e3b\u8981\u5f71\u54cd&#xff1a;<\/p>\n<ul>\n<li>\u6587\u4ef6\u4e0a\u4f20<\/li>\n<li>\u5927\u578b JSON<\/li>\n<li>\u8868\u5355\u63d0\u4ea4<\/li>\n<\/ul>\n<p>\u8d85\u8fc7\u9650\u5236\u65f6&#xff0c;Nginx \u901a\u5e38\u8fd4\u56de&#xff1a;413 Request Entity Too Large<\/p>\n<p>\u8fd9\u662f\u00a0http\u00a0\u7ea7\u522b\u7684\u9ed8\u8ba4\u503c&#xff0c;\u4e5f\u53ef\u4ee5\u5728\u7279\u5b9a\u00a0server\u00a0\u6216\u00a0location\u00a0\u4e2d\u8986\u76d6\u3002<\/p>\n<h4 id=\"%EF%BC%883%EF%BC%89Gzip%20%E5%8E%8B%E7%BC%A9\">&#xff08;3&#xff09;Gzip \u538b\u7f29<\/h4>\n<p>gzip on;<\/p>\n<p>gzip_comp_level 5;<\/p>\n<p>gzip_min_length 256;<\/p>\n<p>gzip_types text\/plain text\/css application\/json application\/javascript application\/xml text\/xml; <\/p>\n<p>\u2460 gzip on<\/p>\n<p>\u5f00\u542f\u54cd\u5e94\u538b\u7f29\u3002<\/p>\n<p>\u4f8b\u5982\u539f\u672c\u4e00\u4e2a CSS \u6587\u4ef6\u6709 100KB&#xff0c;\u538b\u7f29\u540e\u53ef\u80fd\u53ea\u6709 20KB\u3002<\/p>\n<\/p>\n<p>\u8fc7\u7a0b\u5982\u4e0b&#xff1a;<\/p>\n<p>Nginx \u539f\u59cb\u5185\u5bb9<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u2193 gzip \u538b\u7f29<\/p>\n<p>\u8f83\u5c0f\u7684\u6570\u636e<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u2193 \u7f51\u7edc\u4f20\u8f93<\/p>\n<p>\u6d4f\u89c8\u5668\u81ea\u52a8\u89e3\u538b<\/p>\n<p>\u2461 gzip_comp_level 5<\/p>\n<p>\u538b\u7f29\u7b49\u7ea7\u4e3a 5\u3002<\/p>\n<p>\u8303\u56f4\u901a\u5e38\u662f 1&#xff5e;9&#xff1a;<\/p>\n<ul>\n<li>\u7b49\u7ea7\u8d8a\u9ad8&#xff1a;\u6587\u4ef6\u53ef\u80fd\u8d8a\u5c0f<\/li>\n<li>\u7b49\u7ea7\u8d8a\u9ad8&#xff1a;\u6d88\u8017\u7684 CPU \u8d8a\u591a<\/li>\n<\/ul>\n<p>5\u00a0\u662f\u6bd4\u8f83\u5e73\u8861\u7684\u5b9e\u9a8c\u503c\u3002<\/p>\n<p>\u2462 gzip_min_length 256<\/p>\n<p>\u5c0f\u4e8e 256 \u5b57\u8282\u7684\u5185\u5bb9\u4e0d\u538b\u7f29\u3002<\/p>\n<p>\u56e0\u4e3a\u7279\u522b\u5c0f\u7684\u5185\u5bb9\u538b\u7f29\u6536\u76ca\u5f88\u4f4e&#xff0c;\u53cd\u800c\u589e\u52a0\u5904\u7406\u6210\u672c\u3002<\/p>\n<p>\u2463 gzip_types<\/p>\n<p>\u6307\u5b9a\u9700\u8981\u538b\u7f29\u7684\u54cd\u5e94\u7c7b\u578b&#xff1a;<\/p>\n<p>text\/plain<\/p>\n<p>text\/css<\/p>\n<p>application\/json<\/p>\n<p>application\/javascript<\/p>\n<p>application\/xml<\/p>\n<p>text\/xml<\/p>\n<p>\u56fe\u7247\u4e00\u822c\u4e0d\u7528\u518d gzip&#xff0c;\u56e0\u4e3a PNG\u3001JPEG \u7b49\u901a\u5e38\u5df2\u7ecf\u538b\u7f29\u3002<\/p>\n<p>\u9a8c\u8bc1\u662f\u5426\u538b\u7f29&#xff1a;<\/p>\n<p>curl -I \\\\<br \/>\n-H &#039;Accept-Encoding: gzip&#039; \\\\<br \/>\nhttp:\/\/127.0.0.1:18080\/assets\/style.css <\/p>\n<p>\u5982\u679c\u751f\u6548&#xff0c;\u54cd\u5e94\u4e2d\u53ef\u4ee5\u770b\u5230&#xff1a;Content-Encoding: gzip<\/p>\n<h4 id=\"%EF%BC%884%EF%BC%89%E9%99%90%E6%B5%81%E5%8C%BA%E5%9F%9F\">&#xff08;4&#xff09;\u9650\u6d41\u533a\u57df<\/h4>\n<p>limit_req_zone $binary_remote_addr zone&#061;api_limit:10m rate&#061;5r\/s; <\/p>\n<p>\u8fd9\u53ea\u662f\u5b9a\u4e49\u9650\u6d41\u89c4\u5219\u548c\u5b58\u50a8\u533a\u57df&#xff0c;\u8fd8\u6ca1\u6709\u771f\u6b63\u5e94\u7528\u5230\u8bf7\u6c42\u3002<\/p>\n<p>a. $binary_remote_addr<\/p>\n<p>\u8868\u793a\u5ba2\u6237\u7aef IP \u7684\u4e8c\u8fdb\u5236\u5f62\u5f0f\u3002<\/p>\n<\/p>\n<p>Nginx \u6309 IP \u5206\u522b\u8ba1\u6570&#xff1a;<\/p>\n<p>IP 192.168.1.10 \u2192 \u81ea\u5df1\u7684\u8ba1\u6570<\/p>\n<p>IP 192.168.1.11 \u2192 \u81ea\u5df1\u7684\u8ba1\u6570<\/p>\n<p>\u4f7f\u7528\u4e8c\u8fdb\u5236\u5f62\u5f0f\u662f\u4e3a\u4e86\u8282\u7701\u5185\u5b58\u3002<\/p>\n<p>b. zone&#061;api_limit:10m<\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u00a0api_limit\u00a0\u7684\u5171\u4eab\u5185\u5b58\u533a\u57df&#xff0c;\u5927\u5c0f\u4e3a 10MB\u3002<\/p>\n<p>Worker \u8fdb\u7a0b\u4f1a\u5728\u8fd9\u91cc\u5171\u540c\u8bb0\u5f55&#xff1a;\u54ea\u4e2a IP \u6700\u8fd1\u53d1\u4e86\u591a\u5c11\u8bf7\u6c42<\/p>\n<p>\u8fd9\u91cc\u7684\u00a010m\u00a0\u4e0d\u662f\u201c\u5141\u8bb8 10MB \u6d41\u91cf\u201d&#xff0c;\u800c\u662f\u7528\u4e8e\u4fdd\u5b58\u9650\u6d41\u72b6\u6001\u7684\u5185\u5b58\u5927\u5c0f\u3002<\/p>\n<p>c. rate&#061;5r\/s<\/p>\n<p>\u6bcf\u4e2a IP \u5e73\u5747\u6bcf\u79d2\u5141\u8bb8 5 \u4e2a\u8bf7\u6c42\u3002<\/p>\n<p>\u771f\u6b63\u4f7f\u7528\u8fd9\u4e2a\u89c4\u5219\u7684\u4f4d\u7f6e\u5728\u00a0lab.conf&#xff1a;<\/p>\n<p>limit_req zone&#061;api_limit burst&#061;10 nodelay; <\/p>\n<p>\u53ef\u4ee5\u7406\u89e3\u6210&#xff1a;<\/p>\n<p>limit_req_zone \u2192 \u521b\u5efa\u9650\u6d41\u5668<\/p>\n<p>limit_req \u2192 \u5728\u67d0\u4e2a\u63a5\u53e3\u4e0a\u542f\u7528\u9650\u6d41\u5668<\/p>\n<h4 id=\"%EF%BC%885%EF%BC%89%E8%AE%BF%E9%97%AE%E6%97%A5%E5%BF%97%E6%A0%BC%E5%BC%8F\">&#xff08;5&#xff09;\u8bbf\u95ee\u65e5\u5fd7\u683c\u5f0f<\/h4>\n<p>log_format lab &#039;$remote_addr &#8211; [$time_local] &#034;$request&#034; &#039;<br \/>\n&#039;status&#061;$status &#039;<br \/>\n&#039;rt&#061;$request_time &#039;<br \/>\n&#039;urt&#061;$upstream_response_time &#039;<br \/>\n&#039;upstream&#061;$upstream_addr &#039;<br \/>\n&#039;us&#061;$upstream_status &#039;<br \/>\n&#039;ref&#061;&#034;$http_referer&#034; &#039;<br \/>\n&#039;ua&#061;&#034;$http_user_agent&#034;&#039;; <\/p>\n<p>\u8fd9\u91cc\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a\u00a0lab\u00a0\u7684\u65e5\u5fd7\u683c\u5f0f\u3002<\/p>\n<p>\u2460 $remote_addr<\/p>\n<p>\u5ba2\u6237\u7aef IP\u3002<\/p>\n<p>\u5728 Podman\u5b9e\u9a8c\u91cc&#xff0c;\u53ef\u80fd\u770b\u5230\u5bb9\u5668\u7f51\u7edc\u5730\u5740\u3002<\/p>\n<p>\u2461 $time_local<\/p>\n<p>Nginx \u6536\u5230\u8bf7\u6c42\u7684\u65f6\u95f4\u3002<\/p>\n<p>\u2462 $request<\/p>\n<p>\u5b8c\u6574\u8bf7\u6c42\u884c&#xff0c;\u4f8b\u5982&#xff1a;GET \/api\/info HTTP\/1.1<\/p>\n<p>\u2463 $status<\/p>\n<p>Nginx \u6700\u7ec8\u8fd4\u56de\u7684\u72b6\u6001\u7801&#xff1a;<\/p>\n<p>200 \u6b63\u5e38<\/p>\n<p>404 \u5730\u5740\u4e0d\u5b58\u5728<\/p>\n<p>413 \u4e0a\u4f20\u8fc7\u5927<\/p>\n<p>502 \u540e\u7aef\u5f02\u5e38<\/p>\n<p>503 \u9650\u6d41\u6216\u6682\u4e0d\u53ef\u7528<\/p>\n<p>504 \u540e\u7aef\u54cd\u5e94\u8d85\u65f6<\/p>\n<p>\u2464 $request_time<\/p>\n<p>\u4ece Nginx \u6536\u5230\u8bf7\u6c42&#xff0c;\u5230\u53d1\u9001\u5b8c\u54cd\u5e94\u7684\u603b\u65f6\u95f4\u3002<\/p>\n<p>\u65e5\u5fd7\u91cc\u5199\u6210&#xff1a;rt&#061;0.015<\/p>\n<p>\u8868\u793a\u6574\u4e2a\u8bf7\u6c42\u7528\u4e86 0.015 \u79d2\u3002<\/p>\n<p>\u2465 $upstream_response_time<\/p>\n<p>\u540e\u7aef\u54cd\u5e94\u8017\u65f6&#xff1a;urt&#061;0.012<\/p>\n<p>\u5982\u679c\u8bf7\u6c42\u662f\u9759\u6001\u6587\u4ef6&#xff0c;\u6ca1\u6709\u7ecf\u8fc7\u540e\u7aef&#xff0c;\u901a\u5e38\u663e\u793a\u00a0-\u3002<\/p>\n<p>\u2466 $upstream_addr<\/p>\n<p>\u8bf7\u6c42\u4ea4\u7ed9\u4e86\u54ea\u4e2a\u540e\u7aef&#xff1a;upstream&#061;10.89.0.2:8000<\/p>\n<p>\u2467 $upstream_status<\/p>\n<p>\u540e\u7aef\u8fd4\u56de\u7ed9 Nginx \u7684\u72b6\u6001\u7801\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;us&#061;200<\/p>\n<p>\u6ce8\u610f&#xff1a;<\/p>\n<ul>\n<li>$status&#xff1a;Nginx \u6700\u7ec8\u8fd4\u56de\u7ed9\u7528\u6237\u7684\u72b6\u6001<\/li>\n<li>$upstream_status&#xff1a;\u540e\u7aef\u8fd4\u56de\u7ed9 Nginx \u7684\u72b6\u6001<\/li>\n<\/ul>\n<p>\u4e8c\u8005\u4e0d\u4e00\u5b9a\u76f8\u540c\u3002<\/p>\n<p>\u2468 $http_referer<\/p>\n<p>\u7528\u6237\u4ece\u54ea\u4e2a\u9875\u9762\u8fdb\u5165\u5f53\u524d\u5730\u5740\u3002<\/p>\n<p>\u2469 $http_user_agent<\/p>\n<p>\u5ba2\u6237\u7aef\u4fe1\u606f&#xff0c;\u4f8b\u5982\u6d4f\u89c8\u5668\u6216 curl\u3002<\/p>\n<h4 id=\"%EF%BC%886%EF%BC%89%E5%90%AF%E7%94%A8%E8%AE%BF%E9%97%AE%E6%97%A5%E5%BF%97\">&#xff08;6&#xff09;\u542f\u7528\u8bbf\u95ee\u65e5\u5fd7<\/h4>\n<p>access_log \/var\/log\/nginx\/access.log lab; <\/p>\n<p>\u542b\u4e49&#xff1a;<\/p>\n<ul>\n<li>\u65e5\u5fd7\u5199\u5165\u00a0\/var\/log\/nginx\/access.log<\/li>\n<li>\u4f7f\u7528\u521a\u624d\u5b9a\u4e49\u7684\u00a0lab\u00a0\u683c\u5f0f<\/li>\n<\/ul>\n<p>\u67e5\u770b&#xff1a;tail -f ~\/nginx-podman-lab\/logs\/access.log<\/p>\n<h4 id=\"%EF%BC%887%EF%BC%89%E5%8A%A0%E8%BD%BD%E7%BD%91%E7%AB%99%E9%85%8D%E7%BD%AE\">&#xff08;7&#xff09;\u52a0\u8f7d\u7f51\u7ad9\u914d\u7f6e<\/h4>\n<p>include \/etc\/nginx\/conf.d\/*.conf; <\/p>\n<p>\u52a0\u8f7d\u00a0conf.d\u00a0\u76ee\u5f55\u4e0b\u6240\u6709\u00a0.conf\u00a0\u6587\u4ef6\u3002<\/p>\n<p>\u672c\u5b9e\u9a8c\u901a\u8fc7 Podman \u6302\u8f7d\u540e&#xff0c;\u52a0\u8f7d\u7684\u662f&#xff1a;conf\/conf.d\/lab.conf<\/p>\n<p>\u8fd9\u79cd\u62c6\u5206\u65b9\u5f0f\u53ef\u4ee5\u8ba9\u4e00\u4e2a Nginx \u7ba1\u7406\u591a\u4e2a\u7f51\u7ad9&#xff1a;<\/p>\n<p>conf.d\/<\/p>\n<p>\u251c\u2500\u2500 app.conf<\/p>\n<p>\u251c\u2500\u2500 api.conf<\/p>\n<p>\u251c\u2500\u2500 admin.conf<\/p>\n<p>\u2514\u2500\u2500 lab.conf<\/p>\n<h3 id=\"2%E3%80%81lab.conf%EF%BC%9A%E5%AE%9A%E4%B9%89%E5%90%8E%E7%AB%AF%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%BB%84\">2\u3001lab.conf&#xff1a;\u5b9a\u4e49\u540e\u7aef\u670d\u52a1\u5668\u7ec4<\/h3>\n<p>upstream app_backend {<br \/>\n    least_conn;<br \/>\n    keepalive 16;<br \/>\n    server backend-a:8000 weight&#061;3 max_fails&#061;2 fail_timeout&#061;10s;<br \/>\n    server backend-b:8000 weight&#061;1 max_fails&#061;2 fail_timeout&#061;10s;<br \/>\n} <\/p>\n<p>upstream\u00a0\u8868\u793a\u4e00\u7ec4\u540e\u7aef\u670d\u52a1\u5668\u3002<\/p>\n<p>\u540d\u5b57\u662f&#xff1a;app_backend<\/p>\n<p>\u540e\u9762\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u7684\u5199\u6cd5\u4f7f\u7528\u5b83&#xff1a;proxy_pass http:\/\/app_backend;<\/p>\n<h4 id=\"%EF%BC%881%EF%BC%89backend-a%C2%A0%E5%92%8C%C2%A0backend-b%C2%A0\">&#xff08;1&#xff09;backend-a\u00a0\u548c\u00a0backend-b\u00a0<\/h4>\n<p>\u5b83\u4eec\u662f Podman \u5bb9\u5668\u540d\u79f0\u3002<\/p>\n<p>\u4e09\u4e2a\u5bb9\u5668\u52a0\u5165\u4e86\u76f8\u540c\u7f51\u7edc&#xff1a;nginx-lab-net<\/p>\n<\/p>\n<p>Podman \u5185\u90e8 DNS \u4f1a\u628a&#xff1a;<\/p>\n<p>backend-a \u2192 A \u5bb9\u5668\u7684\u5185\u90e8 IP<\/p>\n<p>backend-b \u2192 B \u5bb9\u5668\u7684\u5185\u90e8 IP<\/p>\n<p>\u6240\u4ee5 Nginx \u4e0d\u9700\u8981\u5199\u6b7b IP\u3002<\/p>\n<h4 id=\"%EF%BC%882%EF%BC%89least_conn\">&#xff08;2&#xff09;least_conn<\/h4>\n<p>least_conn; <\/p>\n<p>\u8868\u793a\u4f18\u5148\u628a\u65b0\u8bf7\u6c42\u4ea4\u7ed9\u5f53\u524d\u8fde\u63a5\u8f83\u5c11\u7684\u540e\u7aef\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>A \u5f53\u524d\u6709 10 \u4e2a\u8fde\u63a5<\/p>\n<p>B \u5f53\u524d\u6709 2 \u4e2a\u8fde\u63a5<\/p>\n<p>\u65b0\u8bf7\u6c42\u901a\u5e38\u66f4\u503e\u5411\u4e8e\u4ea4\u7ed9 B\u3002<\/p>\n<p>\u5982\u679c\u4e0d\u5199\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5&#xff0c;\u9ed8\u8ba4\u4f7f\u7528\u8f6e\u8be2\u3002<\/p>\n<h4 id=\"%EF%BC%883%EF%BC%89keepalive%2016\">&#xff08;3&#xff09;keepalive 16<\/h4>\n<p>keepalive 16; <\/p>\n<p>\u8ba9\u6bcf\u4e2a Worker \u6700\u591a\u4fdd\u7559\u4e00\u5b9a\u6570\u91cf\u7684\u7a7a\u95f2\u4e0a\u6e38\u957f\u8fde\u63a5\u3002<\/p>\n<p>\u6ca1\u6709\u8fde\u63a5\u6c60\u65f6&#xff1a;\u6bcf\u6b21\u8bf7\u6c42 \u2192 \u65b0\u5efa\u540e\u7aef\u8fde\u63a5 \u2192 \u8bf7\u6c42\u7ed3\u675f \u2192 \u5173\u95ed<\/p>\n<p>\u4f7f\u7528\u8fde\u63a5\u6c60\u540e&#xff1a;\u5efa\u7acb\u8fde\u63a5 \u2192 \u8bf7\u6c42\u7ed3\u675f \u2192 \u6682\u65f6\u4fdd\u7559 \u2192 \u540e\u7eed\u8bf7\u6c42\u590d\u7528<\/p>\n<p>\u597d\u5904&#xff1a;<\/p>\n<ul>\n<li>\u51cf\u5c11 TCP \u5efa\u8fde\u6210\u672c<\/li>\n<li>\u964d\u4f4e\u540e\u7aef\u538b\u529b<\/li>\n<li>\u63d0\u9ad8\u6027\u80fd<\/li>\n<\/ul>\n<p>\u8fd9\u91cc\u8fd8\u9700\u8981\u5728\u53cd\u4ee3\u4f4d\u7f6e\u4f7f\u7528&#xff1a;<\/p>\n<p>proxy_http_version 1.1;<\/p>\n<p>proxy_set_header Connection &#034;&#034;; <\/p>\n<p>\u5426\u5219\u8fde\u63a5\u590d\u7528\u53ef\u80fd\u65e0\u6cd5\u6309\u9884\u671f\u5de5\u4f5c\u3002<\/p>\n<h4 id=\"%EF%BC%884%EF%BC%89%E5%90%8E%E7%AB%AF%E5%AE%9A%E4%B9%89\">&#xff08;4&#xff09;\u540e\u7aef\u5b9a\u4e49<\/h4>\n<p>server backend-a:8000 weight&#061;3 max_fails&#061;2 fail_timeout&#061;10s;<\/p>\n<p>server backend-b:8000 weight&#061;1 max_fails&#061;2 fail_timeout&#061;10s; <\/p>\n<p>\u2460 weight<\/p>\n<p>A \u6743\u91cd 3&#xff0c;B \u6743\u91cd 1\u3002<\/p>\n<p>\u5927\u4f53\u4e0a\u8868\u793a A \u627f\u62c5\u66f4\u591a\u6d41\u91cf&#xff0c;\u4f46\u56e0\u4e3a\u8fd9\u91cc\u540c\u65f6\u4f7f\u7528\u4e86\u00a0least_conn&#xff0c;\u5b9e\u9645\u9009\u62e9\u8fd8\u4f1a\u8003\u8651\u5f53\u524d\u8fde\u63a5\u6570&#xff0c;\u5e76\u4e0d\u80fd\u673a\u68b0\u7406\u89e3\u6210\u6bcf\u56db\u4e2a\u8bf7\u6c42\u4e00\u5b9a\u662f A\u3001A\u3001A\u3001B\u3002<\/p>\n<p>\u2461 max_fails&#061;2<\/p>\n<p>\u5982\u679c\u5728\u6307\u5b9a\u65f6\u95f4\u5185\u8fde\u7eed\u53d1\u751f\u4e00\u5b9a\u6570\u91cf\u7684\u5931\u8d25&#xff0c;Nginx \u4f1a\u6682\u65f6\u8ba4\u4e3a\u8be5\u8282\u70b9\u4e0d\u53ef\u7528\u3002<\/p>\n<p>\u2462 fail_timeout&#061;10s<\/p>\n<p>\u5b83\u6709\u4e24\u4e2a\u76f8\u5173\u4f5c\u7528&#xff1a;<\/p>\n<ul>\n<li>\u7edf\u8ba1\u5931\u8d25\u7684\u65f6\u95f4\u7a97\u53e3<\/li>\n<li>\u8fbe\u5230\u5931\u8d25\u6b21\u6570\u540e&#xff0c;\u6682\u65f6\u907f\u5f00\u8be5\u8282\u70b9\u7ea6 10 \u79d2<\/li>\n<\/ul>\n<p>\u8fd9\u5c5e\u4e8e\u88ab\u52a8\u5065\u5eb7\u68c0\u67e5&#xff1a;<\/p>\n<p>\u5148\u6709\u771f\u5b9e\u8bf7\u6c42\u5931\u8d25<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u2193<\/p>\n<p>Nginx \u8bb0\u5f55\u5931\u8d25<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u2193<\/p>\n<p>\u8fbe\u5230 max_fails<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u2193<\/p>\n<p>\u6682\u65f6\u5c11\u9009\u6216\u4e0d\u9009\u8be5\u540e\u7aef<\/p>\n<p>\u5b83\u4e0d\u662f\u4e3b\u52a8\u5b9a\u65f6\u8bbf\u95ee\u00a0\/health\u00a0\u7684\u5065\u5eb7\u68c0\u67e5\u3002<\/p>\n<h4 id=\"%EF%BC%885%EF%BC%89server%EF%BC%9A%E5%AE%9A%E4%B9%89%E4%B8%80%E4%B8%AA%E7%BD%91%E7%AB%99\">&#xff08;5&#xff09;server&#xff1a;\u5b9a\u4e49\u4e00\u4e2a\u7f51\u7ad9<\/h4>\n<p>server {<br \/>\n    listen 80;<br \/>\n    server_name localhost lab.local;<br \/>\n} <\/p>\n<p>\u2460 listen 80<\/p>\n<p>Nginx \u5bb9\u5668\u5185\u90e8\u76d1\u542c 80 \u7aef\u53e3\u3002<\/p>\n<p>Podman\u505a\u4e86\u7aef\u53e3\u6620\u5c04&#xff1a;\u7535\u8111 18080 \u2192 Nginx \u5bb9\u5668 80<\/p>\n<p>\u6240\u4ee5\u6d4f\u89c8\u5668\u8bbf\u95ee&#xff1a;http:\/\/127.0.0.1:18080<\/p>\n<p>\u6700\u7ec8\u4f1a\u5230\u8fbe\u5bb9\u5668\u7684 80 \u7aef\u53e3\u3002<\/p>\n<p>\u2461 server_name<\/p>\n<p>server_name localhost lab.local;<\/p>\n<p>\u8868\u793a\u8fd9\u4e2a\u7f51\u7ad9\u5e0c\u671b\u5904\u7406\u7684\u57df\u540d\u662f&#xff1a;<\/p>\n<p>localhost<\/p>\n<p>lab.local<\/p>\n<\/p>\n<p>\u672c\u5b9e\u9a8c\u53ea\u6709\u4e00\u4e2a\u00a0server&#xff0c;\u56e0\u6b64\u4f7f\u7528\u00a0127.0.0.1\u00a0\u901a\u5e38\u4e5f\u4f1a\u843d\u5230\u8fd9\u91cc\u3002<\/p>\n<\/p>\n<p>\u4f01\u4e1a\u4e2d\u53ef\u80fd\u6709\u591a\u4e2a\u00a0server&#xff1a;<\/p>\n<p>server_name api.company.com;<\/p>\n<p>server_name admin.company.com;<\/p>\n<p>server_name www.company.com;<\/p>\n<p>Nginx \u6839\u636e\u8bf7\u6c42\u4e2d\u7684\u00a0Host\u00a0\u9009\u62e9\u5bf9\u5e94\u7f51\u7ad9\u3002<\/p>\n<h4 id=\"%EF%BC%886%EF%BC%89%E5%81%A5%E5%BA%B7%E6%A3%80%E6%9F%A5%C2%A0%2Fhealthz\">&#xff08;6&#xff09;\u5065\u5eb7\u68c0\u67e5\u00a0\/healthz<\/h4>\n<p>location &#061; \/healthz {<br \/>\n    access_log off;<br \/>\n    default_type text\/plain;<br \/>\n    return 200 &#034;ok\\\\n&#034;;<br \/>\n} <\/p>\n<p>\u2460 location &#061; \/healthz<\/p>\n<p>location\u00a0\u6839\u636e URL \u8def\u5f84\u51b3\u5b9a\u5982\u4f55\u5904\u7406\u8bf7\u6c42\u3002<\/p>\n<p>&#061;\u00a0\u8868\u793a\u7cbe\u786e\u5339\u914d&#xff1a;<\/p>\n<p>\/healthz \u2192 \u5339\u914d<\/p>\n<p>\/healthz\/ \u2192 \u4e0d\u5339\u914d<\/p>\n<p>\/healthz\/test \u2192 \u4e0d\u5339\u914d<\/p>\n<p>\u7cbe\u786e\u5339\u914d\u4f18\u5148\u7ea7\u975e\u5e38\u9ad8\u3002<\/p>\n<p>\u2461 access_log off<\/p>\n<p>\u5065\u5eb7\u68c0\u67e5\u901a\u5e38\u6bcf\u51e0\u79d2\u6267\u884c\u4e00\u6b21&#xff0c;\u5982\u679c\u5168\u90e8\u8bb0\u5f55&#xff0c;\u8bbf\u95ee\u65e5\u5fd7\u4f1a\u51fa\u73b0\u5927\u91cf\u65e0\u4ef7\u503c\u5185\u5bb9&#xff0c;\u6240\u4ee5\u8fd9\u91cc\u5173\u95ed\u8bbf\u95ee\u65e5\u5fd7\u3002<\/p>\n<p>\u9519\u8bef\u4ecd\u7136\u53ef\u4ee5\u8fdb\u5165\u9519\u8bef\u65e5\u5fd7\u3002<\/p>\n<p>\u2462 default_type text\/plain<\/p>\n<p>\u544a\u8bc9\u5ba2\u6237\u7aef\u8fd4\u56de\u5185\u5bb9\u662f\u666e\u901a\u6587\u672c\u3002<\/p>\n<p>\u2463 return 200 &#034;ok\\\\n&#034;<\/p>\n<p>Nginx \u76f4\u63a5\u8fd4\u56de&#xff1a;<\/p>\n<p>HTTP \u72b6\u6001\u7801&#xff1a;200<\/p>\n<p>\u5185\u5bb9&#xff1a;ok<\/p>\n<p>\u8bf7\u6c42\u4e0d\u4f1a\u7ecf\u8fc7\u540e\u7aef\u3002<\/p>\n<h4 id=\"%EF%BC%887%EF%BC%89%E9%9D%99%E6%80%81%E7%BD%91%E7%AB%99\">&#xff08;7&#xff09;\u9759\u6001\u7f51\u7ad9<\/h4>\n<p>root \/usr\/share\/nginx\/html;<\/p>\n<p>index index.html; <\/p>\n<p>\u2460 root<\/p>\n<p>\u8bbe\u7f6e\u9759\u6001\u6587\u4ef6\u6839\u76ee\u5f55\u3002<\/p>\n<p>Podman\u628a\u9879\u76ee\u7684\u00a0html\u00a0\u76ee\u5f55\u6302\u8f7d\u5230\u4e86&#xff1a;\/usr\/share\/nginx\/html<\/p>\n<p>\u56e0\u6b64&#xff1a;<\/p>\n<p>\u8bf7\u6c42 \/app.js<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u2192 \/usr\/share\/nginx\/html\/app.js<\/p>\n<p>\u8bf7\u6c42 \/assets\/style.css<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u2192 \/usr\/share\/nginx\/html\/assets\/style.css<\/p>\n<p>\u2461 index index.html<\/p>\n<p>\u8bbf\u95ee\u76ee\u5f55\u00a0\/\u00a0\u65f6&#xff0c;\u9ed8\u8ba4\u67e5\u627e&#xff1a;index.html<\/p>\n<h4 id=\"%EF%BC%888%EF%BC%89try_files%C2%A0%E5%92%8C%20SPA\"><font face=\"-apple-system, SF UI Text, Arial, PingFang SC, Hiragino Sans GB, Microsoft YaHei, WenQuanYi Micro Hei, sans-serif, SimHei, SimSun\">&#xff08;8&#xff09;<\/font>try_files\u00a0\u548c SPA<\/h4>\n<p>location \/ {<\/p>\n<p>    try_files $uri $uri\/ \/index.html;<\/p>\n<p>} <\/p>\n<p>location \/\u00a0\u662f\u6700\u5bbd\u6cdb\u7684\u524d\u7f00\u5339\u914d&#xff0c;\u5927\u591a\u6570\u8bf7\u6c42\u90fd\u80fd\u5339\u914d\u5b83\u3002<\/p>\n<p>try_files\u00a0\u6309\u987a\u5e8f\u5c1d\u8bd5&#xff1a;<\/p>\n<li>$uri&#xff1a;\u6709\u6ca1\u6709\u540c\u540d\u6587\u4ef6<\/li>\n<li>$uri\/&#xff1a;\u6709\u6ca1\u6709\u540c\u540d\u76ee\u5f55<\/li>\n<li>\/index.html&#xff1a;\u90fd\u6ca1\u6709\u65f6\u8fd4\u56de\u9996\u9875<\/li>\n<p>\u4f8b\u5982\u8bf7\u6c42&#xff1a;\/assets\/style.css<\/p>\n<p>Nginx \u67e5\u5230\u6587\u4ef6\u540e\u76f4\u63a5\u8fd4\u56de\u3002<\/p>\n<p>\u8bf7\u6c42&#xff1a;\/user\/profile<\/p>\n<p>\u78c1\u76d8\u6ca1\u6709\u8fd9\u4e2a\u6587\u4ef6&#xff0c;\u4e8e\u662f\u8fd4\u56de&#xff1a;\/index.html<\/p>\n<p>\u8fd9\u9002\u5408 Vue\u3001React \u7b49\u5355\u9875\u5e94\u7528&#xff0c;\u56e0\u4e3a\u00a0\/user\/profile\u00a0\u53ef\u80fd\u662f\u524d\u7aef\u8def\u7531&#xff0c;\u4e0d\u662f\u771f\u5b9e\u6587\u4ef6\u3002<\/p>\n<h4 id=\"%EF%BC%889%EF%BC%89%E9%9D%99%E6%80%81%E8%B5%84%E6%BA%90%E7%BC%93%E5%AD%98\">&#xff08;9&#xff09;\u9759\u6001\u8d44\u6e90\u7f13\u5b58<\/h4>\n<p>location \/assets\/ {<br \/>\n    expires 7d;<br \/>\n    add_header Cache-Control &#034;public&#034;;<br \/>\n    access_log off;<br \/>\n} <\/p>\n<p>\u8fd9\u4e2a\u89c4\u5219\u5339\u914d&#xff1a;<\/p>\n<ul>\n<li>\/assets\/style.css<\/li>\n<li>\/assets\/logo.png<\/li>\n<\/ul>\n<p>\u2460 expires 7d<\/p>\n<p>\u544a\u8bc9\u6d4f\u89c8\u5668\u8d44\u6e90\u53ef\u4ee5\u7f13\u5b58 7 \u5929\u3002<\/p>\n<p>\u8fd9\u6837\u7528\u6237\u7b2c\u4e8c\u6b21\u8bbf\u95ee\u65f6&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u672c\u5730\u7f13\u5b58&#xff0c;\u51cf\u5c11\u8bf7\u6c42\u3002<\/p>\n<p>\u2461 Cache-Control &#034;public&#034;<\/p>\n<p>\u8868\u793a\u8be5\u8d44\u6e90\u5141\u8bb8\u88ab\u6d4f\u89c8\u5668\u3001CDN \u7b49\u516c\u5171\u7f13\u5b58\u4fdd\u5b58\u3002<\/p>\n<p>\u2462 access_log off<\/p>\n<p>\u9759\u6001\u8d44\u6e90\u8bf7\u6c42\u5f88\u591a&#xff0c;\u5b9e\u9a8c\u4e2d\u5173\u95ed\u65e5\u5fd7\u4ee5\u51cf\u5c11\u5e72\u6270\u3002<\/p>\n<p>\u751f\u4ea7\u73af\u5883\u662f\u5426\u5173\u95ed&#xff0c;\u8981\u6839\u636e\u5ba1\u8ba1\u548c\u6392\u969c\u9700\u6c42\u51b3\u5b9a\u3002<\/p>\n<h4 id=\"%EF%BC%8810%EF%BC%89%E6%A0%B8%E5%BF%83%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%C2%A0%2Fapi%2F\" style=\"background-color:transparent\">&#xff08;10&#xff09;\u6838\u5fc3\u53cd\u5411\u4ee3\u7406\u00a0\/api\/<\/h4>\n<p>location \/api\/ {<br \/>\n    limit_req zone&#061;api_limit burst&#061;10 nodelay;<br \/>\n    proxy_pass http:\/\/app_backend\/;<br \/>\n    &#8230;<br \/>\n} <\/p>\n<p>\u5b83\u5339\u914d&#xff1a;<\/p>\n<ul>\n<li>\/api\/info<\/li>\n<li>\/api\/health<\/li>\n<li>\/api\/slow<\/li>\n<\/ul>\n<p>\u2460 \u542f\u7528\u9650\u6d41<\/p>\n<p>limit_req zone&#061;api_limit burst&#061;10 nodelay; <\/p>\n<p>\u4f7f\u7528\u00a0nginx.conf\u00a0\u4e2d\u5b9a\u4e49\u7684&#xff1a;api_limit<\/p>\n<p>a. burst&#061;10<\/p>\n<p>\u5141\u8bb8\u77ed\u65f6\u95f4\u989d\u5916\u7a81\u53d1\u7ea6 10 \u4e2a\u8bf7\u6c42\u3002<\/p>\n<p>\u53ef\u4ee5\u7406\u89e3\u6210&#xff1a;<\/p>\n<ul>\n<li>\u6b63\u5e38\u901f\u5ea6&#xff1a;\u6bcf\u79d2 5 \u4e2a<\/li>\n<li>\u4e34\u65f6\u5141\u8bb8\u4e00\u4e2a\u5c0f\u961f\u5217\/\u6876\u627f\u53d7\u7a81\u53d1<\/li>\n<li>\u8d85\u51fa\u540e\u62d2\u7edd\u8bf7\u6c42<\/li>\n<\/ul>\n<p>b. nodelay<\/p>\n<p>\u7a81\u53d1\u989d\u5ea6\u5185\u7684\u8bf7\u6c42\u7acb\u5373\u5904\u7406&#xff0c;\u4e0d\u8ba9\u5b83\u4eec\u6392\u961f\u6162\u6162\u7b49\u5f85\u3002<\/p>\n<p>\u8d85\u8fc7\u989d\u5ea6\u540e&#xff0c;\u672c\u5b9e\u9a8c\u901a\u5e38\u8fd4\u56de 503\u3002<\/p>\n<p>\u2461 proxy_pass\u00a0\u5c3e\u659c\u6760<\/p>\n<p>proxy_pass http:\/\/app_backend\/; <\/p>\n<p>\u8fd9\u91cc\u672b\u5c3e\u6709\u00a0\/\u3002<\/p>\n<p>\u8bf7\u6c42&#xff1a;\/api\/info<\/p>\n<p>\u8f6c\u53d1\u7ed9\u540e\u7aef\u65f6\u53d8\u6210&#xff1a;\/info<\/p>\n<p>\u4e5f\u5c31\u662f\u00a0\/api\/\u00a0\u524d\u7f00\u88ab\u66ff\u6362\u6210\u00a0\/\u3002<\/p>\n<p>\u8fd9\u662f\u672c\u914d\u7f6e\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u77e5\u8bc6\u70b9\u3002<\/p>\n<p>\u2462 \u4e0a\u6e38\u4f7f\u7528 HTTP\/1.1<\/p>\n<p>proxy_http_version 1.1;<br \/>\nproxy_set_header Connection &#034;&#034;; <\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b&#xff0c;\u4e0a\u6e38\u8fde\u63a5\u53ef\u80fd\u4e0d\u6309\u9884\u671f\u4fdd\u6301\u3002<\/p>\n<p>\u4f7f\u7528 HTTP\/1.1 \u5e76\u6e05\u7a7a\u00a0Connection\u00a0\u8bf7\u6c42\u5934&#xff0c;\u6709\u52a9\u4e8e\u590d\u7528\u524d\u9762\u00a0upstream\u00a0\u4e2d\u914d\u7f6e\u7684 Keepalive \u8fde\u63a5\u3002<\/p>\n<p>\u8fd9\u91cc\u7684\u7a7a\u5b57\u7b26\u4e32\u8868\u793a&#xff1a;<\/p>\n<p>\u4e0d\u8981\u628a\u8fd9\u4e2a\u8bf7\u6c42\u5934\u4f20\u7ed9\u540e\u7aef\u3002<\/p>\n<h4 id=\"%EF%BC%8811%EF%BC%89%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E8%AF%B7%E6%B1%82%E5%A4%B4\">&#xff08;11&#xff09;\u53cd\u5411\u4ee3\u7406\u8bf7\u6c42\u5934<\/h4>\n<p>proxy_set_header Host $host;<br \/>\nproxy_set_header X-Real-IP $remote_addr;<br \/>\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br \/>\nproxy_set_header X-Forwarded-Proto $scheme; <\/p>\n<p>\u2460 Host $host<\/p>\n<p>\u544a\u8bc9\u540e\u7aef&#xff0c;\u7528\u6237\u8bbf\u95ee\u7684\u4e3b\u673a\u540d\u662f\u4ec0\u4e48\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;lab.local<\/p>\n<p>\u2461 X-Real-IP $remote_addr<\/p>\n<p>\u544a\u8bc9\u540e\u7aef&#xff0c;Nginx \u770b\u5230\u7684\u5ba2\u6237\u7aef IP \u662f\u4ec0\u4e48\u3002<\/p>\n<p>\u2462 X-Forwarded-For<\/p>\n<p>\u8bb0\u5f55\u4ee3\u7406\u94fe\u8def\u4e2d\u7684\u5ba2\u6237\u7aef IP\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;\u7528\u6237 \u2192 CDN \u2192 Nginx \u2192 \u540e\u7aef<\/p>\n<p>\u5b83\u53ef\u80fd\u7c7b\u4f3c&#xff1a;203.0.113.10, 10.0.0.5<\/p>\n<p>$proxy_add_x_forwarded_for\u00a0\u4f1a\u4fdd\u7559\u5df2\u6709\u5185\u5bb9&#xff0c;\u518d\u8ffd\u52a0\u5f53\u524d\u5ba2\u6237\u7aef\u5730\u5740\u3002<\/p>\n<p>\u2463 X-Forwarded-Proto $scheme<\/p>\n<p>\u544a\u8bc9\u540e\u7aef\u7528\u6237\u539f\u672c\u4f7f\u7528\u7684\u534f\u8bae&#xff1a;http<\/p>\n<p>\u5982\u679c\u4ee5\u540e\u589e\u52a0 HTTPS&#xff0c;\u5b83\u53ef\u80fd\u662f&#xff1a;https<\/p>\n<p>\u540e\u7aef\u751f\u6210\u8df3\u8f6c\u5730\u5740\u3001Cookie \u6216\u5916\u90e8\u94fe\u63a5\u65f6\u7ecf\u5e38\u9700\u8981\u5b83\u3002<\/p>\n<h4 id=\"%EF%BC%8812%EF%BC%89%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E8%B6%85%E6%97%B6\">&#xff08;12&#xff09;\u53cd\u5411\u4ee3\u7406\u8d85\u65f6<\/h4>\n<p>proxy_connect_timeout 3s;<br \/>\nproxy_send_timeout 30s;<br \/>\nproxy_read_timeout 30s; <\/p>\n<p>\u2460 proxy_connect_timeout<\/p>\n<p>Nginx \u8fde\u63a5\u540e\u7aef\u6700\u591a\u7b49\u5f85 3 \u79d2\u3002<\/p>\n<p>\u4f8b\u5982\u540e\u7aef\u7aef\u53e3\u65e0\u6cd5\u8fde\u63a5&#xff0c;\u7b49\u5f85\u8d85\u8fc7\u65f6\u95f4\u540e\u653e\u5f03\u3002<\/p>\n<p>\u2461 proxy_send_timeout<\/p>\n<p>Nginx \u5411\u540e\u7aef\u53d1\u9001\u8bf7\u6c42\u6570\u636e\u65f6&#xff0c;\u8fde\u7eed\u5199\u6570\u636e\u7684\u7b49\u5f85\u8d85\u65f6\u3002<\/p>\n<p>\u5b83\u5e76\u4e0d\u662f\u6574\u4e2a\u8bf7\u6c42\u7684\u7edd\u5bf9\u603b\u65f6\u957f\u3002<\/p>\n<p>\u2462 proxy_read_timeout<\/p>\n<p>Nginx \u7b49\u5f85\u540e\u7aef\u8fd4\u56de\u6570\u636e\u7684\u95f4\u9694\u8d85\u65f6\u3002<\/p>\n<p>\u5982\u679c\u540e\u7aef\u5728\u6307\u5b9a\u65f6\u95f4\u5185\u4e00\u76f4\u6ca1\u6709\u8fd4\u56de\u65b0\u6570\u636e&#xff0c;Nginx \u4f1a\u7ec8\u6b62\u8bf7\u6c42\u3002<\/p>\n<p>\u666e\u901a API \u4f7f\u7528 30 \u79d2\u53ea\u662f\u5b9e\u9a8c\u503c&#xff0c;\u751f\u4ea7\u4e2d\u5e94\u8be5\u6839\u636e\u4e1a\u52a1\u7279\u70b9\u8bbe\u7f6e\u3002<\/p>\n<h4 id=\"%EF%BC%8813%EF%BC%89%E6%95%85%E6%84%8F%E5%88%B6%E9%80%A0%20504%20%E7%9A%84%C2%A0%2Ftimeout%2F\">&#xff08;13&#xff09;\u6545\u610f\u5236\u9020 504 \u7684\u00a0\/timeout\/<\/h4>\n<p>location \/timeout\/ {<br \/>\n    proxy_pass http:\/\/app_backend\/;<br \/>\n    &#8230;<br \/>\n    proxy_connect_timeout 1s;<br \/>\n    proxy_read_timeout 1s;<br \/>\n} <\/p>\n<p>\u8bbf\u95ee&#xff1a;\/timeout\/slow<\/p>\n<p>\u56e0\u4e3a\u00a0proxy_pass\u00a0\u5e26\u5c3e\u659c\u6760&#xff0c;\u540e\u7aef\u6536\u5230&#xff1a;\/slow<\/p>\n<p>\u540e\u7aef\u7a0b\u5e8f\u6545\u610f\u7b49\u5f85\u7ea6 5 \u79d2&#xff0c;\u4f46 Nginx \u53ea\u5141\u8bb8\u8fde\u7eed\u7b49\u5f85 1 \u79d2&#xff1a;<\/p>\n<p>\u540e\u7aef\u7b49\u5f85 5 \u79d2\u3001Nginx \u53ea\u7b49 1 \u79d2 \u2192 504 Gateway Timeout<\/p>\n<p>\u8fd9\u91cc\u4e3b\u8981\u7528\u6765\u5b66\u4e60\u5982\u4f55\u89c2\u5bdf\u8d85\u65f6\u548c\u9519\u8bef\u65e5\u5fd7&#xff0c;\u4e0d\u80fd\u76f4\u63a5\u7167\u642c\u5230\u751f\u4ea7\u914d\u7f6e\u3002<\/p>\n<h4 id=\"%EF%BC%8814%EF%BC%89%2Fraw%2F%C2%A0%E6%BC%94%E7%A4%BA%E5%B0%BE%E6%96%9C%E6%9D%A0%E5%8C%BA%E5%88%AB\"><font face=\"-apple-system, SF UI Text, Arial, PingFang SC, Hiragino Sans GB, Microsoft YaHei, WenQuanYi Micro Hei, sans-serif, SimHei, SimSun\">&#xff08;14&#xff09;<\/font>\/raw\/\u00a0\u6f14\u793a\u5c3e\u659c\u6760\u533a\u522b<\/h4>\n<p>location \/raw\/ {<br \/>\n    proxy_pass http:\/\/app_backend;<br \/>\n} <\/p>\n<p>\u6ce8\u610f\u8fd9\u91cc\u6ca1\u6709\u5c3e\u659c\u6760\u3002<\/p>\n<p>\u8bbf\u95ee&#xff1a;\/raw\/info<\/p>\n<p>\u540e\u7aef\u6536\u5230\u7684\u4ecd\u7136\u662f&#xff1a;\/raw\/info<\/p>\n<p>\u800c\u4e0d\u662f\u00a0\/info\u3002<\/p>\n<p>\u540e\u7aef\u6ca1\u6709\u00a0\/raw\/info\u00a0\u63a5\u53e3&#xff0c;\u6240\u4ee5\u8fd4\u56de 404\u3002<\/p>\n<p>\u5bf9\u6bd4&#xff1a;<\/p>\n<p>\/api\/info &#043; proxy_pass &#8230;\/ \u2192 \u540e\u7aef\u6536\u5230 \/info<\/p>\n<p>\/raw\/info &#043; proxy_pass &#8230; \u2192 \u540e\u7aef\u6536\u5230 \/raw\/info<\/p>\n<h4 id=\"%EF%BC%8815%EF%BC%89%E7%B2%BE%E7%A1%AE%E5%8C%B9%E9%85%8D%C2%A0%2Fwhoami\">&#xff08;15&#xff09;\u7cbe\u786e\u5339\u914d\u00a0\/whoami<\/h4>\n<p>location &#061; \/whoami {<br \/>\n    default_type application\/json;<br \/>\n    return 200 &#039;{&#034;via&#034;:&#034;nginx-exact-location&#034;,&#034;hint&#034;:&#034;location &#061; has highest priority&#034;}\\\\n&#039;;<br \/>\n} <\/p>\n<p>\u8bbf\u95ee&#xff1a;\/whoami<\/p>\n<p>Nginx \u76f4\u63a5\u8fd4\u56de JSON&#xff0c;\u4e0d\u8bbf\u95ee\u540e\u7aef&#xff0c;\u4e5f\u4e0d\u67e5\u627e\u9759\u6001\u6587\u4ef6\u3002<\/p>\n<p>\u5b83\u7528\u4e8e\u6f14\u793a&#xff1a;location &#061; \/whoami \u6bd4\u666e\u901a\u7684 location \/ \u4f18\u5148\u7ea7\u66f4\u9ad8\u3002<\/p>\n<p>\u4f46\u8bbf\u95ee \/whoami\/test \u4e0d\u4f1a\u5339\u914d\u7cbe\u786e\u89c4\u5219&#xff0c;\u800c\u4f1a\u8fdb\u5165\u00a0location \/\u3002<\/p>\n<h4 id=\"%EF%BC%8816%EF%BC%89%E5%AE%8C%E6%95%B4%E8%AF%B7%E6%B1%82%E6%B5%81%E7%A8%8B\">&#xff08;16&#xff09;\u5b8c\u6574\u8bf7\u6c42\u6d41\u7a0b<\/h4>\n<p>\u2460 \u8bf7\u6c42\u9996\u9875<\/p>\n<p>GET \/<\/p>\n<p>\u2192 server \u76d1\u542c 80<\/p>\n<p>\u2192 \u5339\u914d location \/<\/p>\n<p>\u2192 try_files \u627e\u5230 index.html<\/p>\n<p>\u2192 Nginx \u8fd4\u56de\u9759\u6001\u7f51\u9875<\/p>\n<p>\u2461 \u8bf7\u6c42 CSS<\/p>\n<p>GET \/assets\/style.css<\/p>\n<p>\u2192 \u5339\u914d location \/assets\/<\/p>\n<p>\u2192 \u4ece\u78c1\u76d8\u8bfb\u53d6 CSS<\/p>\n<p>\u2192 \u6dfb\u52a0 7 \u5929\u7f13\u5b58\u5934<\/p>\n<p>\u2192 \u8fd4\u56de\u6d4f\u89c8\u5668<\/p>\n<p>\u2462 \u8bf7\u6c42 API<\/p>\n<p>GET \/api\/info<\/p>\n<p>\u2192 \u5339\u914d location \/api\/<\/p>\n<p>\u2192 \u68c0\u67e5\u9650\u6d41<\/p>\n<p>\u2192 \u53bb\u6389 \/api\/ \u524d\u7f00<\/p>\n<p>\u2192 least_conn \u9009\u62e9 A \u6216 B<\/p>\n<p>\u2192 \u8f6c\u53d1 \/info<\/p>\n<p>\u2192 \u540e\u7aef\u8fd4\u56de JSON<\/p>\n<p>\u2192 Nginx \u8bb0\u5f55 upstream \u548c\u8017\u65f6<\/p>\n<p>\u2192 \u8fd4\u56de\u6d4f\u89c8\u5668<\/p>\n<p>\u2463 \u8bf7\u6c42\u6162\u63a5\u53e3<\/p>\n<p>GET \/timeout\/slow<\/p>\n<p>\u2192 \u5339\u914d location \/timeout\/<\/p>\n<p>\u2192 \u8f6c\u53d1\u540e\u7aef \/slow<\/p>\n<p>\u2192 \u540e\u7aef\u7b49\u5f85 5 \u79d2<\/p>\n<p>\u2192 Nginx \u7b49\u5f85 1 \u79d2\u540e\u8d85\u65f6<\/p>\n<p>\u2192 \u8fd4\u56de 504<\/p>\n<p>\u2464 \u8bf7\u6c42\u00a0\/raw\/info<\/p>\n<p>GET \/raw\/info<\/p>\n<p>\u2192 \u5339\u914d location \/raw\/<\/p>\n<p>\u2192 \u4fdd\u7559\u5b8c\u6574\u8def\u5f84 \/raw\/info<\/p>\n<p>\u2192 \u540e\u7aef\u6ca1\u6709\u8be5\u63a5\u53e3<\/p>\n<p>\u2192 \u8fd4\u56de 404<\/p>\n<h4 id=\"%EF%BC%8817%EF%BC%89%E4%BF%AE%E6%94%B9%E9%85%8D%E7%BD%AE%E7%9A%84%E6%AD%A3%E7%A1%AE%E6%AD%A5%E9%AA%A4\">&#xff08;17&#xff09;\u4fee\u6539\u914d\u7f6e\u7684\u6b63\u786e\u6b65\u9aa4<\/h4>\n<p>\u5148\u68c0\u67e5\u8bed\u6cd5&#xff1a;podman exec nginx-lab nginx -t<\/p>\n<p>\u6210\u529f\u540e\u5e73\u6ed1\u52a0\u8f7d&#xff1a;podman exec nginx-lab nginx -s reload<\/p>\n<p>\u5408\u5e76\u6267\u884c&#xff1a;<\/p>\n<p>podman exec nginx-lab nginx -t &amp;&amp;<\/p>\n<p>podman exec nginx-lab nginx -s reload<\/p>\n<p>\u67e5\u770b\u6700\u7ec8\u5b8c\u6574\u914d\u7f6e&#xff1a;podman exec nginx-lab nginx -T<\/p>\n<p>\u67e5\u770b\u5b9e\u65f6\u65e5\u5fd7&#xff1a;<\/p>\n<p>tail -f logs\/access.log<\/p>\n<p>tail -f logs\/error.log<\/p>\n<p>\u6838\u5fc3&#xff1a;<\/p>\n<p>nginx.conf&#xff1a;\u5168\u5c40\u80fd\u529b<\/p>\n<p>lab.conf&#xff1a;\u7f51\u7ad9\u4e0e\u8def\u7531\u89c4\u5219<\/p>\n<p>upstream&#xff1a;\u540e\u7aef\u540d\u5355<\/p>\n<p>server&#xff1a;\u4e00\u4e2a\u7f51\u7ad9<\/p>\n<p>location&#xff1a;\u4e0d\u540c URL \u600e\u4e48\u5904\u7406<\/p>\n<p>proxy_pass&#xff1a;\u8bf7\u6c42\u8f6c\u7ed9\u8c01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55<br \/>\n\u914d\u7f6e\u6587\u4ef6<br \/>\n1\u3001nginx.conf<br \/>\n2\u3001lab.conf&#xff1a;\u5b9a\u4e49\u540e\u7aef\u670d\u52a1\u5668\u7ec4 \u914d\u7f6e\u6587\u4ef6<br \/>\n\u4e24\u4e2a\u914d\u7f6e\u6587\u4ef6\u7684\u5173\u7cfb\u53ef\u4ee5\u628a\u5b83\u4eec\u7406\u89e3\u6210&#xff1a;<br \/>\nnginx.conf&#xff1a;\u516c\u53f8\u7684\u201c\u603b\u89c4\u7ae0\u5236\u5ea6\u201dlab.conf&#xff1a;\u67d0\u4e2a\u5177\u4f53\u7f51\u7ad9\u7684\u201c\u5de5\u4f5c\u89c4\u5219\u201d<br \/>\n\u52a0\u8f7d\u5173\u7cfb&#xff1a; nginx.conf \u2514\u2500\u2500 http \u00a0 \u00a0 \u2514\u2500\u2500 include \/etc\/nginx\/conf.d\/*.conf \u00a0 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500 lab.conf \u00a0 <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[117,87,78],"topic":[],"class_list":["post-86989","post","type-post","status-publish","format-standard","hentry","category-server","tag-nginx","tag-87","tag-78"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4e0a\u7ae0\u8282\u4e2d\u6587\u4ef6\u7684\u8bb2\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/86989.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4e0a\u7ae0\u8282\u4e2d\u6587\u4ef6\u7684\u8bb2\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 \u914d\u7f6e\u6587\u4ef6 1\u3001nginx.conf 2\u3001lab.conf&#xff1a;\u5b9a\u4e49\u540e\u7aef\u670d\u52a1\u5668\u7ec4 \u914d\u7f6e\u6587\u4ef6 \u4e24\u4e2a\u914d\u7f6e\u6587\u4ef6\u7684\u5173\u7cfb\u53ef\u4ee5\u628a\u5b83\u4eec\u7406\u89e3\u6210&#xff1a; nginx.conf&#xff1a;\u516c\u53f8\u7684\u201c\u603b\u89c4\u7ae0\u5236\u5ea6\u201dlab.conf&#xff1a;\u67d0\u4e2a\u5177\u4f53\u7f51\u7ad9\u7684\u201c\u5de5\u4f5c\u89c4\u5219\u201d \u52a0\u8f7d\u5173\u7cfb&#xff1a; nginx.conf \u2514\u2500\u2500 http \u00a0 \u00a0 \u2514\u2500\u2500 include \/etc\/nginx\/conf.d\/*.conf \u00a0 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500 lab.conf \u00a0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/86989.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-29T07:56:31+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/86989.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/86989.html\",\"name\":\"\u4e0a\u7ae0\u8282\u4e2d\u6587\u4ef6\u7684\u8bb2\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-07-29T07:56:31+00:00\",\"dateModified\":\"2026-07-29T07:56:31+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/86989.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/86989.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/86989.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4e0a\u7ae0\u8282\u4e2d\u6587\u4ef6\u7684\u8bb2\u89e3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4e0a\u7ae0\u8282\u4e2d\u6587\u4ef6\u7684\u8bb2\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/86989.html","og_locale":"zh_CN","og_type":"article","og_title":"\u4e0a\u7ae0\u8282\u4e2d\u6587\u4ef6\u7684\u8bb2\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 \u914d\u7f6e\u6587\u4ef6 1\u3001nginx.conf 2\u3001lab.conf&#xff1a;\u5b9a\u4e49\u540e\u7aef\u670d\u52a1\u5668\u7ec4 \u914d\u7f6e\u6587\u4ef6 \u4e24\u4e2a\u914d\u7f6e\u6587\u4ef6\u7684\u5173\u7cfb\u53ef\u4ee5\u628a\u5b83\u4eec\u7406\u89e3\u6210&#xff1a; nginx.conf&#xff1a;\u516c\u53f8\u7684\u201c\u603b\u89c4\u7ae0\u5236\u5ea6\u201dlab.conf&#xff1a;\u67d0\u4e2a\u5177\u4f53\u7f51\u7ad9\u7684\u201c\u5de5\u4f5c\u89c4\u5219\u201d \u52a0\u8f7d\u5173\u7cfb&#xff1a; nginx.conf \u2514\u2500\u2500 http \u00a0 \u00a0 \u2514\u2500\u2500 include \/etc\/nginx\/conf.d\/*.conf \u00a0 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500 lab.conf \u00a0","og_url":"https:\/\/www.wsisp.com\/helps\/86989.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-07-29T07:56:31+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/86989.html","url":"https:\/\/www.wsisp.com\/helps\/86989.html","name":"\u4e0a\u7ae0\u8282\u4e2d\u6587\u4ef6\u7684\u8bb2\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-07-29T07:56:31+00:00","dateModified":"2026-07-29T07:56:31+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/86989.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/86989.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/86989.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u4e0a\u7ae0\u8282\u4e2d\u6587\u4ef6\u7684\u8bb2\u89e3"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/86989","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=86989"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/86989\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=86989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=86989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=86989"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=86989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}