{"id":7034,"date":"2026-03-03T16:46:10","date_gmt":"2026-03-03T08:46:10","guid":{"rendered":"https:\/\/t.n-years.com\/?p=7034"},"modified":"2026-03-03T16:46:10","modified_gmt":"2026-03-03T08:46:10","slug":"nginx-openresty-%e5%92%8c-webserver-%e9%83%bd%e8%83%bd%e5%a4%84%e7%90%86%e7%9a%84%e9%80%bb%e8%be%91%e6%9d%83%e8%a1%a1","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=7034","title":{"rendered":"Nginx\/OpenResty \u548c WebServer \u90fd\u80fd\u5904\u7406\u7684\u903b\u8f91\u6743\u8861"},"content":{"rendered":"<blockquote>\n<p>Gemini \u751f\u6210<\/p>\n<\/blockquote>\n<p>\u8fd9\u662f\u79fb\u52a8\u67b6\u6784\u8bbe\u8ba1\u4e2d\u975e\u5e38\u7ecf\u5178\u7684\u4e00\u4e2a\u6743\u8861\uff08Trade-off\uff09\u95ee\u9898\u3002\u4f5c\u4e3a\u6280\u672f\u987e\u95ee\uff0c\u6211\u5efa\u8bae\u4ece<strong>\u201c\u6267\u884c\u6548\u7387\u201d<\/strong>\u548c<strong>\u201c\u4e1a\u52a1\u6df1\u5ea6\u201d<\/strong>\u4e24\u4e2a\u7ef4\u5ea6\u6765\u5212\u5206\u8fb9\u754c\u3002<\/p>\n<p>\u6838\u5fc3\u539f\u5219\u662f\uff1a<strong>\u8d8a\u9760\u8fd1\u7528\u6237\u7684\u903b\u8f91\uff0c\u8d8a\u9002\u5408\u5728 Nginx\/OpenResty \u505a\uff1b\u8d8a\u9760\u8fd1\u6570\u636e\u7684\u903b\u8f91\uff0c\u8d8a\u9002\u5408\u5728 WebServer\uff08\u5982 Java\/Go\/Node.js\uff09\u505a\u3002<\/strong><\/p>\n<hr \/>\n<h3>1. \u6df1\u5ea6\u5bf9\u6bd4\uff1a\u4ee5\u201c\u9274\u6743\u201d\u4e3a\u4f8b<\/h3>\n<p>\u65e2\u7136\u4f60\u63d0\u5230\u4e86\u9274\u6743\uff0c\u6211\u4eec\u6765\u770b\u770b\u5728\u4e24\u4e2a\u5c42\u7ea7\u5b9e\u73b0\u6709\u4ec0\u4e48\u4e0d\u540c\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7ef4\u5ea6<\/th>\n<th>Nginx (OpenResty\/Lua)<\/th>\n<th>WebServer (Spring\/Go\/Express)<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u6027\u80fd<\/strong><\/td>\n<td><strong>\u6781\u9ad8<\/strong>\u3002\u5728\u8bf7\u6c42\u8fdb\u5165\u540e\u7aef\u524d\u5c31\u62e6\u622a\uff0c\u4fdd\u62a4\u540e\u7aef\u7ebf\u7a0b\u8d44\u6e90\u3002<\/td>\n<td><strong>\u8f83\u4f4e<\/strong>\u3002\u8bf7\u6c42\u5fc5\u987b\u7ecf\u8fc7\u5b8c\u6574\u7684 Web \u6846\u67b6\u6808\uff08\u53cd\u5e8f\u5217\u5316\u3001\u8fc7\u6ee4\u5668\u7b49\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u5f00\u53d1\u96be\u5ea6<\/strong><\/td>\n<td><strong>\u4e2d\u7b49<\/strong>\u3002\u9700\u8981\u7f16\u5199 Lua\uff0c\u4e14\u8c03\u8bd5\u5de5\u5177\u94fe\u4e0d\u5982\u901a\u7528\u8bed\u8a00\u6210\u719f\u3002<\/td>\n<td><strong>\u4f4e<\/strong>\u3002\u53ef\u4ee5\u76f4\u63a5\u5229\u7528\u6210\u719f\u7684\u751f\u6001\uff08\u5982 Spring Security, Passport\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u4e1a\u52a1\u6df1\u5ea6<\/strong><\/td>\n<td><strong>\u6d45<\/strong>\u3002\u9002\u5408\u505a\u901a\u7528\u7684 JWT \u6821\u9a8c\u3001\u7b7e\u540d\u9a8c\u8bc1\u3001\u7b80\u5355\u9ed1\u540d\u5355\u3002<\/td>\n<td><strong>\u6df1<\/strong>\u3002\u9002\u5408\u5904\u7406\u201c\u8be5\u7528\u6237\u662f\u5426\u6709\u6743\u4fee\u6539\u67d0\u6761\u7279\u5b9a\u7684\u8ba2\u5355\u8bb0\u5f55\u201d\u8fd9\u79cd\u903b\u8f91\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u54cd\u5e94\u901f\u5ea6<\/strong><\/td>\n<td>\u6beb\u79d2\u7ea7\u62e6\u622a\u975e\u6cd5\u8bf7\u6c42\u3002<\/td>\n<td>\u5373\u4f7f\u662f\u88ab\u62d2\u7edd\u7684\u8bf7\u6c42\uff0c\u4e5f\u4f1a\u6d88\u8017\u4e00\u5b9a\u7684\u540e\u7aef\u7b97\u529b\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>2. \u573a\u666f\u5212\u5206\u5efa\u8bae<\/h3>\n<h4>\ud83d\ude80 \u9002\u5408\u5728 Nginx (OpenResty) \u505a\u7684\u573a\u666f<\/h4>\n<p>\u8fd9\u4e9b\u573a\u666f\u901a\u5e38\u5c5e\u4e8e\u201c\u6d41\u91cf\u63a7\u5236\u201d\u548c\u201c\u534f\u8bae\u8f6c\u6362\u201d\uff0c\u5b83\u4eec\u4e0d\u4f9d\u8d56\u590d\u6742\u7684\u4e1a\u52a1\u72b6\u6001\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u5168\u5c40\u9632\u5fa1\u4e0e\u9650\u6d41<\/strong>\uff1a<\/p>\n<ul>\n<li>IP \u9ed1\u767d\u540d\u5355\u3001\u9632\u6b62\u6076\u610f\u722c\u866b\u3001WAF\uff08Web \u5e94\u7528\u9632\u706b\u5899\uff09\u3002<\/li>\n<li>\u57fa\u4e8e\u7528\u6237 ID \u6216 API \u7684\u4ee4\u724c\u6876\u9650\u6d41\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9ad8\u6027\u80fd\u7f13\u5b58<\/strong>\uff1a<\/p>\n<ul>\n<li><strong>\u914d\u7f6e\u4e0b\u53d1<\/strong>\uff1a\u79fb\u52a8\u7aef App \u542f\u52a8\u65f6\u7684\u914d\u7f6e\u5f00\u5173\uff08\u4ece Shared Dict \u6216 Redis \u76f4\u63a5\u8fd4\u56de\uff09\u3002<\/li>\n<li><strong>\u9759\u6001\u8d44\u6e90\u52a0\u901f<\/strong>\uff1a\u52a8\u6001\u8c03\u6574\u56fe\u7247\u5c3a\u5bf8\u6216\u683c\u5f0f\u8f6c\u6362\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u52a8\u6001\u8def\u7531\u4e0e\u7070\u5ea6<\/strong>\uff1a<\/p>\n<ul>\n<li><strong>AB Testing<\/strong>\uff1a\u6839\u636e Cookie \u6216 Header \u91cc\u7684\u8bbe\u5907 ID\uff0c\u5c06 10% \u7684\u6d41\u91cf\u5bfc\u5411\u65b0\u7248\u670d\u52a1\u5668\u3002<\/li>\n<li><strong>\u7248\u672c\u517c\u5bb9<\/strong>\uff1a\u5728\u7f51\u5173\u5c42\u505a\u7b80\u5355\u7684\u8bf7\u6c42\/\u54cd\u5e94\u683c\u5f0f\u6620\u5c04\uff0c\u9002\u914d\u8001\u7248\u672c App\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8f7b\u91cf\u7ea7\u9274\u6743<\/strong>\uff1a<\/p>\n<ul>\n<li><strong>JWT \u9a8c\u7b7e<\/strong>\uff1a\u53ea\u68c0\u67e5 Token \u662f\u5426\u5408\u6cd5\u3001\u662f\u5426\u8fc7\u671f\uff0c\u4e0d\u67e5\u6570\u636e\u5e93\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h4>\ud83c\udfd7\ufe0f \u9002\u5408\u5728 WebServer \u505a\u7684\u573a\u666f<\/h4>\n<p>\u8fd9\u4e9b\u573a\u666f\u6d89\u53ca\u201c\u6838\u5fc3\u4e1a\u52a1\u89c4\u5219\u201d\u548c\u201c\u4e8b\u52a1\u5904\u7406\u201d\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u590d\u6742\u4e1a\u52a1\u903b\u8f91<\/strong>\uff1a<\/p>\n<ul>\n<li>\u591a\u8868\u5173\u8054\u67e5\u8be2\u3001\u8ba2\u5355\u72b6\u6001\u6d41\u8f6c\u3001\u652f\u4ed8\u903b\u8f91\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u7ec6\u7c92\u5ea6\u6743\u9650 (RBAC)<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5224\u65ad\u201c\u5f53\u524d\u7528\u6237\u662f\u5426\u5c5e\u4e8e\u8be5\u534f\u4f5c\u7ec4\u201d\uff0c\u8fd9\u9700\u8981\u6df1\u5ea6\u67e5\u8be2\u6570\u636e\u5e93\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u91cd\u578b\u8ba1\u7b97\u4e0e\u96c6\u6210<\/strong>\uff1a<\/p>\n<ul>\n<li>PDF \u751f\u6210\u3001\u56fe\u7247\u6df1\u5ea6\u5904\u7406\u3001\u8c03\u7528\u7b2c\u4e09\u65b9\u590d\u6742\u7684 SDK\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>ORM \u4e0e\u6570\u636e\u6301\u4e45\u5316<\/strong>\uff1a<\/p>\n<ul>\n<li>\u6240\u6709\u6d89\u53ca\u6570\u636e\u5e93\u4e8b\u52a1\uff08Transaction\uff09\u7684\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr \/>\n<h3>3. \u9ec4\u91d1\u6cd5\u5219\uff1a\u6df7\u5408\u67b6\u6784 (Hybrid)<\/h3>\n<p>\u5728 15 \u5e74\u7684\u7ecf\u9a8c\u4e2d\uff0c\u6211\u6700\u63a8\u5d07\u7684\u65b9\u6848\u662f <strong>\u201c\u4e8c\u6bb5\u5f0f\u6821\u9a8c\u201d<\/strong>\uff1a<\/p>\n<ol>\n<li><strong>Nginx \u5c42\uff08\u521d\u7b5b\uff09<\/strong>\uff1a\u6821\u9a8c <code>Token<\/code> \u7684\u7b7e\u540d\u662f\u5426\u6b63\u786e\u3002\u5982\u679c\u7b7e\u540d\u90fd\u4e0d\u5bf9\uff0c\u76f4\u63a5 401\uff0c\u8fde\u540e\u7aef\u670d\u52a1\u5668\u7684\u8fb9\u90fd\u522b\u8ba9\u5b83\u78b0\u3002<\/li>\n<li><strong>WebServer \u5c42\uff08\u6df1\u68c0\uff09<\/strong>\uff1a\u6821\u9a8c\u8be5 <code>User-ID<\/code> \u662f\u5426\u88ab\u5c01\u7981\uff0c\u6216\u662f\u5426\u6709\u64cd\u4f5c\u8be5\u8d44\u6e90\u7684\u6743\u9650\u3002<\/li>\n<\/ol>\n<blockquote>\n<p><strong>\u6279\u5224\u6027\u5efa\u8bae\uff1a<\/strong><br \/>\n\u5982\u679c\u4f60\u7684\u56e2\u961f\u6ca1\u6709\u4e13\u95e8\u7684\u8fd0\u7ef4\u6216 Nginx \u5f00\u53d1\u4eba\u5458\uff0c<strong>\u4e0d\u8981\u5f3a\u884c\u628a\u903b\u8f91\u5f80 Lua \u642c<\/strong>\u3002\u867d\u7136\u6027\u80fd\u597d\uff0c\u4f46\u5982\u679c Lua \u4ee3\u7801\u5199\u5f97\u70c2\uff08\u6bd4\u5982\u5728\u5faa\u73af\u91cc\u505a\u540c\u6b65\u963b\u585e\u8c03\u7528\uff09\uff0c\u5b83\u4f1a\u628a\u6574\u4e2a Nginx \u6302\u6b7b\uff0c\u5bfc\u81f4\u6240\u6709 API \u762b\u75ea\u3002<\/p>\n<\/blockquote>\n<hr \/>\n<h3>\u843d\u5730\u5bfc\u5411\uff1a\u63a5\u4e0b\u6765\u7684\u6b65\u9aa4<\/h3>\n<p>\u5982\u679c\u4f60\u6b63\u9762\u4e34\u4e00\u4e2a\u5177\u4f53\u7684\u9009\u578b\uff0c\u4f60\u53ef\u4ee5\u95ee\u81ea\u5df1\u4e00\u4e2a\u95ee\u9898\uff1a<strong>\u201c\u8fd9\u4e2a\u903b\u8f91\u5982\u679c\u5931\u8d25\u4e86\uff0c\u662f\u5426\u53ef\u4ee5\u4e0d\u7528\u770b\u6570\u636e\u5e93\u5c31\u80fd\u51b3\u5b9a\uff1f\u201d<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u662f\uff08\u5982\uff1a\u683c\u5f0f\u4e0d\u5bf9\u3001\u7b7e\u540d\u4e0d\u5bf9\u3001\u9891\u7387\u592a\u5feb\uff09\uff0c\u8bf7\u5728 <strong>Nginx<\/strong> \u505a\u3002<\/li>\n<li>\u5982\u679c\u5426\uff08\u5982\uff1a\u4f59\u989d\u4e0d\u8db3\u3001\u5e93\u5b58\u4e0d\u591f\u3001\u5bc6\u7801\u9519\u8bef\uff09\uff0c\u8bf7\u5728 <strong>WebServer<\/strong> \u505a\u3002<\/li>\n<\/ul>\n<p><strong>\u4f60\u60f3\u8ba9\u6211\u5e2e\u4f60\u9488\u5bf9\u4f60\u76ee\u524d\u9879\u76ee\u4e2d\u7684\u67d0\u4e2a\u5177\u4f53\u903b\u8f91\uff08\u6bd4\u5982\uff1a\u9a8c\u8bc1\u7801\u6821\u9a8c\u3001\u6216\u662f\u591a\u7ef4\u5ea6\u9650\u6d41\uff09\u8bbe\u8ba1\u4e00\u4e0b\u5b83\u5e94\u8be5\u5982\u4f55\u5728 Nginx \u548c WebServer \u4e4b\u95f4\u5206\u5e03\u5417\uff1f<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Gemini \u751f\u6210 \u8fd9\u662f\u79fb\u52a8\u67b6\u6784\u8bbe\u8ba1\u4e2d\u975e\u5e38\u7ecf\u5178\u7684\u4e00\u4e2a\u6743\u8861\uff08Trade-off\uff09\u95ee\u9898\u3002\u4f5c\u4e3a\u6280\u672f\u987e\u95ee\uff0c\u6211\u5efa\u8bae\u4ece\u201c\u6267&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=7034\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[123],"tags":[],"class_list":["post-7034","post","type-post","status-publish","format-standard","hentry","category-123"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/7034","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7034"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/7034\/revisions"}],"predecessor-version":[{"id":7035,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/7034\/revisions\/7035"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}