{"id":57,"date":"2021-01-14T17:06:00","date_gmt":"2021-01-14T09:06:00","guid":{"rendered":"http:\/\/www.cygzs.net\/?p=57"},"modified":"2021-01-14T17:06:00","modified_gmt":"2021-01-14T09:06:00","slug":"nginx%e5%8f%98%e9%87%8f%e4%bd%bf%e7%94%a8%e6%96%b9%e6%b3%95%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.cygzs.net\/?p=57","title":{"rendered":"nginx\u53d8\u91cf\u4f7f\u7528\u65b9\u6cd5\u8be6\u89e3"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u4f7f\u7528\u7684\u5c31\u662f\u4e00\u95e8\u5fae\u578b\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u8bb8\u591a\u771f\u5b9e\u4e16\u754c\u91cc\u7684 Nginx\u914d\u7f6e\u6587\u4ef6\u5176\u5b9e\u5c31\u662f\u4e00\u4e2a\u4e00\u4e2a\u7684\u5c0f\u7a0b\u5e8f\u3002\u5f53\u7136\uff0c\u662f\u4e0d\u662f\u201c\u56fe\u7075\u5b8c\u5168\u7684\u201d\u6682\u4e14\u4e0d\u8bba\uff0c\u81f3\u5c11\u636e\u6211\u89c2\u5bdf\uff0c\u5b83\u5728\u8bbe\u8ba1\u4e0a\u53d7 Perl \u548c BourneShell \u8fd9\u4e24\u79cd\u8bed\u8a00\u7684\u5f71\u54cd\u5f88\u5927\u3002\u5728\u8fd9\u4e00\u70b9\u4e0a\uff0c\u76f8\u6bd4 Apache \u548c Lighttpd \u7b49\u5176\u4ed6 Web \u670d\u52a1\u5668\u7684\u914d\u7f6e\u8bb0\u6cd5\uff0c\u4e0d\u80fd\u4e0d\u8bf4\u7b97\u662fNginx \u7684\u4e00\u5927\u7279\u8272\u4e86\u3002\u65e2\u7136\u662f\u7f16\u7a0b\u8bed\u8a00\uff0c\u4e00\u822c\u4e5f\u5c31\u5c11\u4e0d\u4e86\u201c\u53d8\u91cf\u201d\u8fd9\u79cd\u4e1c\u897f\uff08\u5f53\u7136\uff0cHaskell\u8fd9\u6837\u5947\u602a\u7684\u51fd\u6570\u5f0f\u8bed\u8a00\u9664\u5916\u4e86\uff09\u3002<br><br>\u719f\u6089 Perl\u3001Bourne Shell\u3001C\/C++\u7b49\u547d\u4ee4\u5f0f\u7f16\u7a0b\u8bed\u8a00\u7684\u670b\u53cb\u80af\u5b9a\u77e5\u9053\uff0c\u53d8\u91cf\u8bf4\u767d\u4e86\u5c31\u662f\u5b58\u653e\u201c\u503c\u201d\u7684\u5bb9\u5668\u3002\u800c\u6240\u8c13\u201c\u503c\u201d\uff0c\u5728\u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\u91cc\uff0c\u65e2\u53ef\u4ee5\u662f 3.14\u8fd9\u6837\u7684\u6570\u503c\uff0c\u4e5f\u53ef\u4ee5\u662f hello world \u8fd9\u6837\u7684\u5b57\u7b26\u4e32\uff0c\u751a\u81f3\u53ef\u4ee5\u662f\u50cf\u6570\u7ec4\u3001\u54c8\u5e0c\u8868\u8fd9\u6837\u7684\u590d\u6742\u6570\u636e\u7ed3\u6784\u3002\u7136\u800c\uff0c\u5728 Nginx\u914d\u7f6e\u4e2d\uff0c\u53d8\u91cf\u53ea\u80fd\u5b58\u653e\u4e00\u79cd\u7c7b\u578b\u7684\u503c\uff0c\u56e0\u4e3a\u4e5f\u53ea\u5b58\u5728\u4e00\u79cd\u7c7b\u578b\u7684\u503c\uff0c\u90a3\u5c31\u662f\u5b57\u7b26\u4e32\u3002<br><br>\u6bd4\u5982\u6211\u4eec\u7684 nginx.conf \u6587\u4ef6\u4e2d\u6709\u4e0b\u9762\u8fd9\u4e00\u884c\u914d\u7f6e\uff1a<br><br><br>set $a&#8221;hello world&#8221;;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u4f7f\u7528\u4e86\u6807\u51c6 ngx_rewrite \u6a21\u5757\u7684 set \u914d\u7f6e\u6307\u4ee4\u5bf9\u53d8\u91cf $a \u8fdb\u884c\u4e86\u8d4b\u503c\u64cd\u4f5c\u3002\u7279\u522b\u5730\uff0c\u6211\u4eec\u628a\u5b57\u7b26\u4e32 helloworld \u8d4b\u7ed9\u4e86\u5b83\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u770b\u5230\uff0cNginx \u53d8\u91cf\u540d\u524d\u9762\u6709\u4e00\u4e2a $ \u7b26\u53f7\uff0c\u8fd9\u662f\u8bb0\u6cd5\u4e0a\u7684\u8981\u6c42\u3002\u6240\u6709\u7684 Nginx \u53d8\u91cf\u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\u5f15\u7528\u65f6\u90fd\u987b\u5e26\u4e0a$ \u524d\u7f00\u3002\u8fd9\u79cd\u8868\u793a\u65b9\u6cd5\u548c Perl\u3001PHP \u8fd9\u4e9b\u8bed\u8a00\u662f\u76f8\u4f3c\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u867d\u7136 $ \u8fd9\u6837\u7684\u53d8\u91cf\u524d\u7f00\u4fee\u9970\u4f1a\u8ba9\u6b63\u7edf\u7684 Java \u548c C#\u7a0b\u5e8f\u5458\u4e0d\u8212\u670d\uff0c\u4f46\u8fd9\u79cd\u8868\u793a\u65b9\u6cd5\u7684\u597d\u5904\u4e5f\u662f\u663e\u800c\u6613\u89c1\u7684\uff0c\u90a3\u5c31\u662f\u53ef\u4ee5\u76f4\u63a5\u628a\u53d8\u91cf\u5d4c\u5165\u5230\u5b57\u7b26\u4e32\u5e38\u91cf\u4e2d\u4ee5\u6784\u9020\u51fa\u65b0\u7684\u5b57\u7b26\u4e32\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">set $ahello;<br>set $b &#8220;$a,$a&#8221;;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u6211\u4eec\u901a\u8fc7\u5df2\u6709\u7684 Nginx \u53d8\u91cf $a \u7684\u503c\uff0c\u6765\u6784\u9020\u53d8\u91cf $b \u7684\u503c\uff0c\u4e8e\u662f\u8fd9\u4e24\u6761\u6307\u4ee4\u987a\u5e8f\u6267\u884c\u5b8c\u4e4b\u540e\uff0c$a \u7684\u503c\u662f hello\uff0c\u800c$b \u7684\u503c\u5219\u662f hello, hello. \u8fd9\u79cd\u6280\u672f\u5728 Perl \u4e16\u754c\u91cc\u88ab\u79f0\u4e3a\u201c\u53d8\u91cf\u63d2\u503c\u201d\uff08variableinterpolation\uff09\uff0c\u5b83\u8ba9\u4e13\u95e8\u7684\u5b57\u7b26\u4e32\u62fc\u63a5\u8fd0\u7b97\u7b26\u53d8\u5f97\u4e0d\u518d\u90a3\u4e48\u5fc5\u8981\u3002\u6211\u4eec\u5728\u8fd9\u91cc\u4e5f\u4e0d\u59a8\u91c7\u7528\u6b64\u672f\u8bed\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u6bd4\u8f83\u5b8c\u6574\u7684\u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">server{<br>listen 8080;<br>location \/test {<br>set $foo hello;<br>echo &#8220;foo: $foo&#8221;;<br>}<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u4f8b\u5b50\u7701\u7565\u4e86 nginx.conf \u914d\u7f6e\u6587\u4ef6\u4e2d\u6700\u5916\u56f4\u7684 http \u914d\u7f6e\u5757\u4ee5\u53ca events \u914d\u7f6e\u5757\u3002\u4f7f\u7528 curl \u8fd9\u4e2a HTTP\u5ba2\u6237\u7aef\u5728\u547d\u4ee4\u884c\u4e0a\u8bf7\u6c42\u8fd9\u4e2a \/test \u63a5\u53e3\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl&#8217;http:\/\/localhost:8080\/test&#8217;<br>foo:hello<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u7b2c\u4e09\u65b9 ngx_echo \u6a21\u5757\u7684 echo \u914d\u7f6e\u6307\u4ee4\u5c06 $foo \u53d8\u91cf\u7684\u503c\u4f5c\u4e3a\u5f53\u524d\u8bf7\u6c42\u7684\u54cd\u5e94\u4f53\u8f93\u51fa\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u770b\u5230\uff0cecho\u914d\u7f6e\u6307\u4ee4\u7684\u53c2\u6570\u4e5f\u652f\u6301\u201c\u53d8\u91cf\u63d2\u503c\u201d\u3002\u4e0d\u8fc7\uff0c\u9700\u8981\u8bf4\u660e\u7684\u662f\uff0c\u5e76\u975e\u6240\u6709\u7684\u914d\u7f6e\u6307\u4ee4\u90fd\u652f\u6301\u201c\u53d8\u91cf\u63d2\u503c\u201d\u3002\u4e8b\u5b9e\u4e0a\uff0c\u6307\u4ee4\u53c2\u6570\u662f\u5426\u5141\u8bb8\u201c\u53d8\u91cf\u63d2\u503c\u201d\uff0c\u53d6\u51b3\u4e8e\u8be5\u6307\u4ee4\u7684\u5b9e\u73b0\u6a21\u5757\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6211\u4eec\u60f3\u901a\u8fc7 echo \u6307\u4ee4\u76f4\u63a5\u8f93\u51fa\u542b\u6709\u201c\u7f8e\u5143\u7b26\u201d\uff08$\uff09\u7684\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u6709\u6ca1\u6709\u529e\u6cd5\u628a\u7279\u6b8a\u7684 $\u5b57\u7b26\u7ed9\u8f6c\u4e49\u6389\u5462\uff1f\u7b54\u6848\u662f\u5426\u5b9a\u7684\uff08\u81f3\u5c11\u5230\u76ee\u524d\u6700\u65b0\u7684 Nginx \u7a33\u5b9a\u72481.0.10\uff09\u3002\u4e0d\u8fc7\u5e78\u8fd0\u7684\u662f\uff0c\u6211\u4eec\u53ef\u4ee5\u7ed5\u8fc7\u8fd9\u4e2a\u9650\u5236\uff0c\u6bd4\u5982\u901a\u8fc7\u4e0d\u652f\u6301\u201c\u53d8\u91cf\u63d2\u503c\u201d\u7684\u6a21\u5757\u914d\u7f6e\u6307\u4ee4\u4e13\u95e8\u6784\u9020\u51fa\u53d6\u503c\u4e3a $ \u7684 Nginx\u53d8\u91cf\uff0c\u7136\u540e\u518d\u5728 echo \u4e2d\u4f7f\u7528\u8fd9\u4e2a\u53d8\u91cf\u3002\u770b\u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">geo $dollar{<br>default &#8220;$&#8221;;<br>}<br>server{<br>listen 8080;<br>location \/test {<br>echo &#8220;This is a dollar sign: $dollar&#8221;;<br>}<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6d4b\u8bd5\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl&#8217;http:\/\/localhost:8080\/test&#8217;<br>This is adollar sign: $<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u7528\u5230\u4e86\u6807\u51c6\u6a21\u5757 ngx_geo \u63d0\u4f9b\u7684\u914d\u7f6e\u6307\u4ee4 geo \u6765\u4e3a\u53d8\u91cf $dollar \u8d4b\u4e88\u5b57\u7b26\u4e32&#8221;$&#8221;\uff0c\u8fd9\u6837\u6211\u4eec\u5728\u4e0b\u9762\u9700\u8981\u4f7f\u7528\u7f8e\u5143\u7b26\u7684\u5730\u65b9\uff0c\u5c31\u76f4\u63a5\u5f15\u7528\u6211\u4eec\u7684 $dollar \u53d8\u91cf\u5c31\u53ef\u4ee5\u4e86\u3002\u5176\u5b9e ngx_geo\u6a21\u5757\u6700\u5e38\u89c4\u7684\u7528\u6cd5\u662f\u6839\u636e\u5ba2\u6237\u7aef\u7684 IP \u5730\u5740\u5bf9\u6307\u5b9a\u7684 Nginx \u53d8\u91cf\u8fdb\u884c\u8d4b\u503c\uff0c\u8fd9\u91cc\u53ea\u662f\u501f\u7528\u5b83\u4ee5\u4fbf\u201c\u65e0\u6761\u4ef6\u5730\u201d\u5bf9\u6211\u4eec\u7684 $dollar\u53d8\u91cf\u8d4b\u4e88\u201c\u7f8e\u5143\u7b26\u201d\u8fd9\u4e2a\u503c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u201c\u53d8\u91cf\u63d2\u503c\u201d\u7684\u4e0a\u4e0b\u6587\u4e2d\uff0c\u8fd8\u6709\u4e00\u79cd\u7279\u6b8a\u60c5\u51b5\uff0c\u5373\u5f53\u5f15\u7528\u7684\u53d8\u91cf\u540d\u4e4b\u540e\u7d27\u8ddf\u7740\u53d8\u91cf\u540d\u7684\u6784\u6210\u5b57\u7b26\u65f6\uff08\u6bd4\u5982\u540e\u8ddf\u5b57\u6bcd\u3001\u6570\u5b57\u4ee5\u53ca\u4e0b\u5212\u7ebf\uff09\uff0c\u6211\u4eec\u5c31\u9700\u8981\u4f7f\u7528\u7279\u522b\u7684\u8bb0\u6cd5\u6765\u6d88\u9664\u6b67\u4e49\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">server{<br>listen 8080;<br>location \/test {<br>set $first &#8220;hello &#8220;;<br>echo &#8220;${first}world&#8221;;<br>}<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\uff0c\u6211\u4eec\u5728 echo \u914d\u7f6e\u6307\u4ee4\u7684\u53c2\u6570\u503c\u4e2d\u5f15\u7528\u53d8\u91cf $first \u7684\u65f6\u5019\uff0c\u540e\u9762\u7d27\u8ddf\u7740 world \u8fd9\u4e2a\u5355\u8bcd\uff0c\u6240\u4ee5\u5982\u679c\u76f4\u63a5\u5199\u4f5c&#8221;$firstworld&#8221; \u5219 Nginx \u201c\u53d8\u91cf\u63d2\u503c\u201d\u8ba1\u7b97\u5f15\u64ce\u4f1a\u5c06\u4e4b\u8bc6\u522b\u4e3a\u5f15\u7528\u4e86\u53d8\u91cf $firstworld.\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u96be\u9898\uff0cNginx \u7684\u5b57\u7b26\u4e32\u8bb0\u6cd5\u652f\u6301\u4f7f\u7528\u82b1\u62ec\u53f7\u5728 $ \u4e4b\u540e\u628a\u53d8\u91cf\u540d\u56f4\u8d77\u6765\uff0c\u6bd4\u5982\u8fd9\u91cc\u7684 ${first}.\u4e0a\u9762\u8fd9\u4e2a\u4f8b\u5b50\u7684\u8f93\u51fa\u662f\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl&#8217;http:\/\/localhost:8080\/test<br>helloworld<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">set \u6307\u4ee4\uff08\u4ee5\u53ca\u524d\u9762\u63d0\u5230\u7684 geo \u6307\u4ee4\uff09\u4e0d\u4ec5\u6709\u8d4b\u503c\u7684\u529f\u80fd\uff0c\u5b83\u8fd8\u6709\u521b\u5efa Nginx\u53d8\u91cf\u7684\u526f\u4f5c\u7528\uff0c\u5373\u5f53\u4f5c\u4e3a\u8d4b\u503c\u5bf9\u8c61\u7684\u53d8\u91cf\u5c1a\u4e0d\u5b58\u5728\u65f6\uff0c\u5b83\u4f1a\u81ea\u52a8\u521b\u5efa\u8be5\u53d8\u91cf\u3002\u6bd4\u5982\u5728\u4e0a\u9762\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5982\u679c $a \u8fd9\u4e2a\u53d8\u91cf\u5c1a\u672a\u521b\u5efa\uff0c\u5219 set\u6307\u4ee4\u4f1a\u81ea\u52a8\u521b\u5efa $a \u8fd9\u4e2a\u7528\u6237\u53d8\u91cf\u3002\u5982\u679c\u6211\u4eec\u4e0d\u521b\u5efa\u5c31\u76f4\u63a5\u4f7f\u7528\u5b83\u7684\u503c\uff0c\u5219\u4f1a\u62a5\u9519\u3002\u4f8b\u5982<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">server{<br>listen 8080;<br>location \/bad {<br>echo $foo;<br>}<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u65f6 Nginx \u670d\u52a1\u5668\u4f1a\u62d2\u7edd\u52a0\u8f7d\u914d\u7f6e:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">[emerg]unknown &#8220;foo&#8221; variable<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u662f\u7684\uff0c\u6211\u4eec\u751a\u81f3\u90fd\u65e0\u6cd5\u542f\u52a8\u670d\u52a1\uff01<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6709\u8da3\u7684\u662f\uff0cNginx \u53d8\u91cf\u7684\u521b\u5efa\u548c\u8d4b\u503c\u64cd\u4f5c\u53d1\u751f\u5728\u5168\u7136\u4e0d\u540c\u7684\u65f6\u95f4\u9636\u6bb5\u3002Nginx \u53d8\u91cf\u7684\u521b\u5efa\u53ea\u80fd\u53d1\u751f\u5728 Nginx\u914d\u7f6e\u52a0\u8f7d\u7684\u65f6\u5019\uff0c\u6216\u8005\u8bf4 Nginx\u542f\u52a8\u7684\u65f6\u5019\uff1b\u800c\u8d4b\u503c\u64cd\u4f5c\u5219\u53ea\u4f1a\u53d1\u751f\u5728\u8bf7\u6c42\u5b9e\u9645\u5904\u7406\u7684\u65f6\u5019\u3002\u8fd9\u610f\u5473\u7740\u4e0d\u521b\u5efa\u800c\u76f4\u63a5\u4f7f\u7528\u53d8\u91cf\u4f1a\u5bfc\u81f4\u542f\u52a8\u5931\u8d25\uff0c\u540c\u65f6\u4e5f\u610f\u5473\u7740\u6211\u4eec\u65e0\u6cd5\u5728\u8bf7\u6c42\u5904\u7406\u65f6\u52a8\u6001\u5730\u521b\u5efa\u65b0\u7684Nginx \u53d8\u91cf\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Nginx \u53d8\u91cf\u4e00\u65e6\u521b\u5efa\uff0c\u5176\u53d8\u91cf\u540d\u7684\u53ef\u89c1\u8303\u56f4\u5c31\u662f\u6574\u4e2a Nginx \u914d\u7f6e\uff0c\u751a\u81f3\u53ef\u4ee5\u8de8\u8d8a\u4e0d\u540c\u865a\u62df\u4e3b\u673a\u7684 server\u914d\u7f6e\u5757\u3002\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">server{<br>listen 8080;<br>location \/foo {<br>echo &#8220;foo = [$foo]&#8221;;<br>}<br>location \/bar {<br>set $foo 32;<br>echo &#8220;foo = [$foo]&#8221;;<br>}<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u6211\u4eec\u5728 location \/bar \u4e2d\u7528 set \u6307\u4ee4\u521b\u5efa\u4e86\u53d8\u91cf $foo\uff0c\u4e8e\u662f\u5728\u6574\u4e2a\u914d\u7f6e\u6587\u4ef6\u4e2d\u8fd9\u4e2a\u53d8\u91cf\u90fd\u662f\u53ef\u89c1\u7684\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u5728location \/foo \u4e2d\u76f4\u63a5\u5f15\u7528\u8fd9\u4e2a\u53d8\u91cf\u800c\u4e0d\u7528\u62c5\u5fc3 Nginx \u4f1a\u62a5\u9519\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u5728\u547d\u4ee4\u884c\u4e0a\u7528 curl \u5de5\u5177\u8bbf\u95ee\u8fd9\u4e24\u4e2a\u63a5\u53e3\u7684\u7ed3\u679c\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl&#8217;http:\/\/localhost:8080\/foo&#8217;<br>foo =[]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl&#8217;http:\/\/localhost:8080\/bar&#8217;<br>foo =[32]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl&#8217;http:\/\/localhost:8080\/foo&#8217;<br>foo =[]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u8fd9\u4e2a\u4f8b\u5b50\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0cset \u6307\u4ee4\u56e0\u4e3a\u662f\u5728 location \/bar \u4e2d\u4f7f\u7528\u7684\uff0c\u6240\u4ee5\u8d4b\u503c\u64cd\u4f5c\u53ea\u4f1a\u5728\u8bbf\u95ee \/bar\u7684\u8bf7\u6c42\u4e2d\u6267\u884c\u3002\u800c\u8bf7\u6c42 \/foo \u63a5\u53e3\u65f6\uff0c\u6211\u4eec\u603b\u662f\u5f97\u5230\u7a7a\u7684 $foo \u503c\uff0c\u56e0\u4e3a\u7528\u6237\u53d8\u91cf\u672a\u8d4b\u503c\u5c31\u8f93\u51fa\u7684\u8bdd\uff0c\u5f97\u5230\u7684\u4fbf\u662f\u7a7a\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u8fd9\u4e2a\u4f8b\u5b50\u6211\u4eec\u53ef\u4ee5\u7aa5\u89c1\u7684\u53e6\u4e00\u4e2a\u91cd\u8981\u7279\u6027\u662f\uff0cNginx\u53d8\u91cf\u540d\u7684\u53ef\u89c1\u8303\u56f4\u867d\u7136\u662f\u6574\u4e2a\u914d\u7f6e\uff0c\u4f46\u6bcf\u4e2a\u8bf7\u6c42\u90fd\u6709\u6240\u6709\u53d8\u91cf\u7684\u72ec\u7acb\u526f\u672c\uff0c\u6216\u8005\u8bf4\u90fd\u6709\u5404\u53d8\u91cf\u7528\u6765\u5b58\u653e\u503c\u7684\u5bb9\u5668\u7684\u72ec\u7acb\u526f\u672c\uff0c\u5f7c\u6b64\u4e92\u4e0d\u5e72\u6270\u3002\u6bd4\u5982\u524d\u9762\u6211\u4eec\u8bf7\u6c42\u4e86\/bar \u63a5\u53e3\u540e\uff0c$foo \u53d8\u91cf\u88ab\u8d4b\u4e88\u4e86\u503c 32\uff0c\u4f46\u5b83\u4e1d\u6beb\u4e0d\u4f1a\u5f71\u54cd\u540e\u7eed\u5bf9 \/foo \u63a5\u53e3\u7684\u8bf7\u6c42\u6240\u5bf9\u5e94\u7684 $foo\u503c\uff08\u5b83\u4ecd\u7136\u662f\u7a7a\u7684\uff01\uff09\uff0c\u56e0\u4e3a\u5404\u4e2a\u8bf7\u6c42\u90fd\u6709\u81ea\u5df1\u72ec\u7acb\u7684 $foo \u53d8\u91cf\u7684\u526f\u672c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bf9\u4e8e Nginx \u65b0\u624b\u6765\u8bf4\uff0c\u6700\u5e38\u89c1\u7684\u9519\u8bef\u4e4b\u4e00\uff0c\u5c31\u662f\u5c06 Nginx\u53d8\u91cf\u7406\u89e3\u6210\u67d0\u79cd\u5728\u8bf7\u6c42\u4e4b\u95f4\u5168\u5c40\u5171\u4eab\u7684\u4e1c\u897f\uff0c\u6216\u8005\u8bf4\u201c\u5168\u5c40\u53d8\u91cf\u201d\u3002\u800c\u4e8b\u5b9e\u4e0a\uff0cNginx \u53d8\u91cf\u7684\u751f\u547d\u671f\u662f\u4e0d\u53ef\u80fd\u8de8\u8d8a\u8bf7\u6c42\u8fb9\u754c\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5173\u4e8e Nginx \u53d8\u91cf\u7684\u53e6\u4e00\u4e2a\u5e38\u89c1\u8bef\u533a\u662f\u8ba4\u4e3a\u53d8\u91cf\u5bb9\u5668\u7684\u751f\u547d\u671f\uff0c\u662f\u4e0e location\u914d\u7f6e\u5757\u7ed1\u5b9a\u7684\u3002\u5176\u5b9e\u4e0d\u7136\u3002\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u6d89\u53ca\u201c\u5185\u90e8\u8df3\u8f6c\u201d\u7684\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">server{<br>listen 8080;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">location \/foo {<br>set $a hello;<br>echo_exec \/bar;<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">location \/bar {<br>echo &#8220;a = [$a]&#8221;;<br>}<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u6211\u4eec\u5728 location \/foo \u4e2d\uff0c\u4f7f\u7528\u7b2c\u4e09\u65b9\u6a21\u5757 ngx_echo \u63d0\u4f9b\u7684 echo_exec \u914d\u7f6e\u6307\u4ee4\uff0c\u53d1\u8d77\u5230location \/bar \u7684\u201c\u5185\u90e8\u8df3\u8f6c\u201d\u3002\u6240\u8c13\u201c\u5185\u90e8\u8df3\u8f6c\u201d\uff0c\u5c31\u662f\u5728\u5904\u7406\u8bf7\u6c42\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4e8e\u670d\u52a1\u5668\u5185\u90e8\uff0c\u4ece\u4e00\u4e2a location\u8df3\u8f6c\u5230\u53e6\u4e00\u4e2a location \u7684\u8fc7\u7a0b\u3002\u8fd9\u4e0d\u540c\u4e8e\u5229\u7528 HTTP \u72b6\u6001\u7801 301 \u548c 302 \u6240\u8fdb\u884c\u7684\u201c\u5916\u90e8\u8df3\u8f6c\u201d\uff0c\u56e0\u4e3a\u540e\u8005\u662f\u7531HTTP \u5ba2\u6237\u7aef\u914d\u5408\u8fdb\u884c\u8df3\u8f6c\u7684\uff0c\u800c\u4e14\u5728\u5ba2\u6237\u7aef\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u6d4f\u89c8\u5668\u5730\u5740\u680f\u8fd9\u6837\u7684\u754c\u9762\uff0c\u770b\u5230\u8bf7\u6c42\u7684 URL \u5730\u5740\u53d1\u751f\u4e86\u53d8\u5316\u3002\u5185\u90e8\u8df3\u8f6c\u548cBourne Shell\uff08\u6216 Bash\uff09\u4e2d\u7684 exec \u547d\u4ee4\u5f88\u50cf\uff0c\u90fd\u662f\u201c\u6709\u53bb\u65e0\u56de\u201d\u3002\u53e6\u4e00\u4e2a\u76f8\u8fd1\u7684\u4f8b\u5b50\u662f C \u8bed\u8a00\u4e2d\u7684 goto\u8bed\u53e5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u65e2\u7136\u662f\u5185\u90e8\u8df3\u8f6c\uff0c\u5f53\u524d\u6b63\u5728\u5904\u7406\u7684\u8bf7\u6c42\u5c31\u8fd8\u662f\u539f\u6765\u90a3\u4e2a\uff0c\u53ea\u662f\u5f53\u524d\u7684 location \u53d1\u751f\u4e86\u53d8\u5316\uff0c\u6240\u4ee5\u8fd8\u662f\u539f\u6765\u7684\u90a3\u4e00\u5957 Nginx\u53d8\u91cf\u7684\u5bb9\u5668\u526f\u672c\u3002\u5bf9\u5e94\u5230\u4e0a\u4f8b\uff0c\u5982\u679c\u6211\u4eec\u8bf7\u6c42\u7684\u662f \/foo \u8fd9\u4e2a\u63a5\u53e3\uff0c\u90a3\u4e48\u6574\u4e2a\u5de5\u4f5c\u6d41\u7a0b\u662f\u8fd9\u6837\u7684\uff1a\u5148\u5728 location \/foo \u4e2d\u901a\u8fc7set \u6307\u4ee4\u5c06 $a \u53d8\u91cf\u7684\u503c\u8d4b\u4e3a\u5b57\u7b26\u4e32 hello\uff0c\u7136\u540e\u901a\u8fc7 echo_exec \u6307\u4ee4\u53d1\u8d77\u5185\u90e8\u8df3\u8f6c\uff0c\u53c8\u8fdb\u5165\u5230 location\/bar \u4e2d\uff0c\u518d\u8f93\u51fa $a \u53d8\u91cf\u7684\u503c\u3002\u56e0\u4e3a $a \u8fd8\u662f\u539f\u6765\u7684 $a\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u671f\u671b\u5f97\u5230 hello\u8fd9\u884c\u8f93\u51fa\u3002\u6d4b\u8bd5\u8bc1\u5b9e\u4e86\u8fd9\u4e00\u70b9\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl localhost:8080\/foo<br>a = [hello]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u5982\u679c\u6211\u4eec\u4ece\u5ba2\u6237\u7aef\u76f4\u63a5\u8bbf\u95ee \/bar \u63a5\u53e3\uff0c\u5c31\u4f1a\u5f97\u5230\u7a7a\u7684 $a \u53d8\u91cf\u7684\u503c\uff0c\u56e0\u4e3a\u5b83\u4f9d\u8d56\u4e8e location \/foo \u6765\u5bf9 $a\u8fdb\u884c\u521d\u59cb\u5316\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u9762\u8fd9\u4e2a\u4f8b\u5b50\u6211\u4eec\u770b\u5230\uff0c\u4e00\u4e2a\u8bf7\u6c42\u5728\u5176\u5904\u7406\u8fc7\u7a0b\u4e2d\uff0c\u5373\u4f7f\u7ecf\u5386\u591a\u4e2a\u4e0d\u540c\u7684 location \u914d\u7f6e\u5757\uff0c\u5b83\u4f7f\u7528\u7684\u8fd8\u662f\u540c\u4e00\u5957 Nginx\u53d8\u91cf\u7684\u526f\u672c\u3002\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u9996\u6b21\u6d89\u53ca\u5230\u4e86\u201c\u5185\u90e8\u8df3\u8f6c\u201d\u8fd9\u4e2a\u6982\u5ff5\u3002\u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0c\u6807\u51c6 ngx_rewrite \u6a21\u5757\u7684 rewrite\u914d\u7f6e\u6307\u4ee4\u5176\u5b9e\u4e5f\u53ef\u4ee5\u53d1\u8d77\u201c\u5185\u90e8\u8df3\u8f6c\u201d\uff0c\u4f8b\u5982\u4e0a\u9762\u90a3\u4e2a\u4f8b\u5b50\u7528 rewrite \u914d\u7f6e\u6307\u4ee4\u53ef\u4ee5\u6539\u5199\u6210\u4e0b\u9762\u8fd9\u6837\u7684\u5f62\u5f0f\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">server{<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">listen 8080;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">location \/foo {<br>set $a hello;<br>rewrite ^ \/bar;<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">location \/bar {<br>echo &#8220;a = [$a]&#8221;;<br>}<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u6548\u679c\u548c\u4f7f\u7528 echo_exec \u662f\u5b8c\u5168\u76f8\u540c\u7684\u3002\u540e\u9762\u6211\u4eec\u8fd8\u4f1a\u4e13\u95e8\u4ecb\u7ecd\u8fd9\u4e2a rewrite \u6307\u4ee4\u7684\u66f4\u591a\u7528\u6cd5\uff0c\u6bd4\u5982\u53d1\u8d77 301 \u548c 302\u8fd9\u6837\u7684\u201c\u5916\u90e8\u8df3\u8f6c\u201d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u9762\u8fd9\u4e2a\u4f8b\u5b50\u6211\u4eec\u770b\u5230\uff0cNginx \u53d8\u91cf\u503c\u5bb9\u5668\u7684\u751f\u547d\u671f\u662f\u4e0e\u5f53\u524d\u6b63\u5728\u5904\u7406\u7684\u8bf7\u6c42\u7ed1\u5b9a\u7684\uff0c\u800c\u4e0e location \u65e0\u5173\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u524d\u9762\u6211\u4eec\u63a5\u89e6\u5230\u7684\u90fd\u662f\u901a\u8fc7 set \u6307\u4ee4\u9690\u5f0f\u521b\u5efa\u7684 Nginx\u53d8\u91cf\u3002\u8fd9\u4e9b\u53d8\u91cf\u6211\u4eec\u4e00\u822c\u79f0\u4e3a\u201c\u7528\u6237\u81ea\u5b9a\u4e49\u53d8\u91cf\u201d\uff0c\u6216\u8005\u66f4\u7b80\u5355\u4e00\u4e9b\uff0c\u201c\u7528\u6237\u53d8\u91cf\u201d\u3002\u65e2\u7136\u6709\u201c\u7528\u6237\u81ea\u5b9a\u4e49\u53d8\u91cf\u201d\uff0c\u81ea\u7136\u4e5f\u5c31\u6709\u7531 Nginx\u6838\u5fc3\u548c\u5404\u4e2a Nginx \u6a21\u5757\u63d0\u4f9b\u7684\u201c\u9884\u5b9a\u4e49\u53d8\u91cf\u201d\uff0c\u6216\u8005\u8bf4\u201c\u5185\u5efa\u53d8\u91cf\u201d\uff08builtin variables\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Nginx \u5185\u5efa\u53d8\u91cf\u6700\u5e38\u89c1\u7684\u7528\u9014\u5c31\u662f\u83b7\u53d6\u5173\u4e8e\u8bf7\u6c42\u6216\u54cd\u5e94\u7684\u5404\u79cd\u4fe1\u606f\u3002\u4f8b\u5982\u7531 ngx_http_core \u6a21\u5757\u63d0\u4f9b\u7684\u5185\u5efa\u53d8\u91cf$uri\uff0c\u53ef\u4ee5\u7528\u6765\u83b7\u53d6\u5f53\u524d\u8bf7\u6c42\u7684 URI\uff08\u7ecf\u8fc7\u89e3\u7801\uff0c\u5e76\u4e14\u4e0d\u542b\u8bf7\u6c42\u53c2\u6570\uff09\uff0c\u800c $request_uri \u5219\u7528\u6765\u83b7\u53d6\u8bf7\u6c42\u6700\u539f\u59cb\u7684 URI\uff08\u672a\u7ecf\u89e3\u7801\uff0c\u5e76\u4e14\u5305\u542b\u8bf7\u6c42\u53c2\u6570\uff09\u3002\u8bf7\u770b\u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">location\/test {<br>echo &#8220;uri = $uri&#8221;;<br>echo &#8220;request_uri = $request_uri&#8221;;<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u4e3a\u4e86\u7b80\u5355\u8d77\u89c1\uff0c\u8fde server \u914d\u7f6e\u5757\u4e5f\u7701\u7565\u4e86\uff0c\u548c\u524d\u9762\u6240\u6709\u793a\u4f8b\u4e00\u6837\uff0c\u6211\u4eec\u76d1\u542c\u7684\u4f9d\u7136\u662f 8080 \u7aef\u53e3\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u91cc\uff0c\u6211\u4eec\u628a$uri \u548c $request_uri \u7684\u503c\u8f93\u51fa\u5230\u54cd\u5e94\u4f53\u4e2d\u53bb\u3002\u4e0b\u9762\u6211\u4eec\u7528\u4e0d\u540c\u7684\u8bf7\u6c42\u6765\u6d4b\u8bd5\u4e00\u4e0b\u8fd9\u4e2a \/test \u63a5\u53e3\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl&#8217;http:\/\/localhost:8080\/test&#8217;<br>uri = \/test<br>request_uri= \/test<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl&#8217;http:\/\/localhost:8080\/test?a=3&amp;b=4&#8242;<br>uri =\/test<br>request_uri= \/test?a=3&amp;b=4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl&#8217;http:\/\/localhost:8080\/test\/hello world?a=3&amp;b=4&#8242;<br>uri =\/test\/hello world<br>request_uri= \/test\/hello world?a=3&amp;b=4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53e6\u4e00\u4e2a\u7279\u522b\u5e38\u7528\u7684\u5185\u5efa\u53d8\u91cf\u5176\u5b9e\u5e76\u4e0d\u662f\u5355\u72ec\u4e00\u4e2a\u53d8\u91cf\uff0c\u800c\u662f\u6709\u65e0\u9650\u591a\u53d8\u79cd\u7684\u4e00\u7fa4\u53d8\u91cf\uff0c\u5373\u540d\u5b57\u4ee5 arg_ \u5f00\u5934\u7684\u6240\u6709\u53d8\u91cf\uff0c\u6211\u4eec\u4f30\u4e14\u79f0\u4e4b\u4e3a$arg_XXX \u53d8\u91cf\u7fa4\u3002\u4e00\u4e2a\u4f8b\u5b50\u662f $arg_name\uff0c\u8fd9\u4e2a\u53d8\u91cf\u7684\u503c\u662f\u5f53\u524d\u8bf7\u6c42\u540d\u4e3a name \u7684 URI\u53c2\u6570\u7684\u503c\uff0c\u800c\u4e14\u8fd8\u662f\u672a\u89e3\u7801\u7684\u539f\u59cb\u5f62\u5f0f\u7684\u503c\u3002\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u6bd4\u8f83\u5b8c\u6574\u7684\u793a\u4f8b\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">location\/test {<br>echo &#8220;name: $arg_name&#8221;;<br>echo &#8220;class: $arg_class&#8221;;<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u540e\u5728\u547d\u4ee4\u884c\u4e0a\u4f7f\u7528\u5404\u79cd\u53c2\u6570\u7ec4\u5408\u53bb\u8bf7\u6c42\u8fd9\u4e2a \/test \u63a5\u53e3\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl&#8217;http:\/\/localhost:8080\/test&#8217;<br>name:<br>class:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl&#8217;http:\/\/localhost:8080\/test?name=Tom&amp;class=3&#8242;<br>name:Tom<br>class:3<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl&#8217;http:\/\/localhost:8080\/test?name=hello world&amp;class=9&#8242;<br>name: helloworld<br>class:9<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u5b9e $arg_name \u4e0d\u4ec5\u53ef\u4ee5\u5339\u914d name \u53c2\u6570\uff0c\u4e5f\u53ef\u4ee5\u5339\u914d NAME \u53c2\u6570\uff0c\u6291\u6216\u662f Name\uff0c\u7b49\u7b49\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl&#8217;http:\/\/localhost:8080\/test?NAME=Marry&#8217;<br>name:Marry<br>class:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl&#8217;http:\/\/localhost:8080\/test?Name=Jimmy&#8217;<br>name:Jimmy<br>class:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Nginx \u4f1a\u5728\u5339\u914d\u53c2\u6570\u540d\u4e4b\u524d\uff0c\u81ea\u52a8\u628a\u539f\u59cb\u8bf7\u6c42\u4e2d\u7684\u53c2\u6570\u540d\u8c03\u6574\u4e3a\u5168\u90e8\u5c0f\u5199\u7684\u5f62\u5f0f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u60f3\u5bf9 URI \u53c2\u6570\u503c\u4e2d\u7684 %XX \u8fd9\u6837\u7684\u7f16\u7801\u5e8f\u5217\u8fdb\u884c\u89e3\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9 ngx_set_misc \u6a21\u5757\u63d0\u4f9b\u7684 set__uri\u914d\u7f6e\u6307\u4ee4\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">location\/test {<br>set__uri $name $arg_name;<br>set__uri $class $arg_class;<br>echo &#8220;name: $name&#8221;;<br>echo &#8220;class: $class&#8221;;<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u73b0\u5728\u6211\u4eec\u518d\u770b\u4e00\u4e0b\u6548\u679c\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl &#8216;http:\/\/localhost:8080\/test?name=helloworld&amp;class=9&#8217;<br>name: hello world<br>class: 9<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7a7a\u683c\u679c\u7136\u88ab\u89e3\u7801\u51fa\u6765\u4e86\uff01<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u8fd9\u4e2a\u4f8b\u5b50\u6211\u4eec\u540c\u65f6\u53ef\u4ee5\u770b\u5230\uff0c\u8fd9\u4e2a set__uri \u6307\u4ee4\u4e5f\u50cf set \u6307\u4ee4\u90a3\u6837\uff0c\u62e5\u6709\u81ea\u52a8\u521b\u5efa Nginx\u53d8\u91cf\u7684\u529f\u80fd\u3002\u540e\u9762\u6211\u4eec\u8fd8\u4f1a\u4e13\u95e8\u4ecb\u7ecd\u5230 ngx_set_misc \u6a21\u5757\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u50cf $arg_XXX \u8fd9\u79cd\u7c7b\u578b\u7684\u53d8\u91cf\u62e5\u6709\u65e0\u7a77\u65e0\u5c3d\u79cd\u53ef\u80fd\u7684\u540d\u5b57\uff0c\u6240\u4ee5\u5b83\u4eec\u5e76\u4e0d\u5bf9\u5e94\u4efb\u4f55\u5b58\u653e\u503c\u7684\u5bb9\u5668\u3002\u800c\u4e14\u8fd9\u79cd\u53d8\u91cf\u5728 Nginx\u6838\u5fc3\u4e2d\u662f\u7ecf\u8fc7\u7279\u522b\u5904\u7406\u7684\uff0c\u7b2c\u4e09\u65b9 Nginx \u6a21\u5757\u662f\u4e0d\u80fd\u63d0\u4f9b\u8fd9\u6837\u5145\u6ee1\u9b54\u6cd5\u7684\u5185\u5efa\u53d8\u91cf\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7c7b\u4f3c $arg_XXX \u7684\u5185\u5efa\u53d8\u91cf\u8fd8\u6709\u4e0d\u5c11\uff0c\u6bd4\u5982\u7528\u6765\u53d6 cookie \u503c\u7684 $cookie_XXX \u53d8\u91cf\u7fa4\uff0c\u7528\u6765\u53d6\u8bf7\u6c42\u5934\u7684$http_XXX \u53d8\u91cf\u7fa4\uff0c\u4ee5\u53ca\u7528\u6765\u53d6\u54cd\u5e94\u5934\u7684 $sent_http_XXX \u53d8\u91cf\u7fa4\u3002\u8fd9\u91cc\u5c31\u4e0d\u4e00\u4e00\u4ecb\u7ecd\u4e86\uff0c\u611f\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u53c2\u8003ngx_http_core \u6a21\u5757\u7684\u5b98\u65b9\u6587\u6863\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9700\u8981\u6307\u51fa\u7684\u662f\uff0c\u8bb8\u591a\u5185\u5efa\u53d8\u91cf\u90fd\u662f\u53ea\u8bfb\u7684\uff0c\u6bd4\u5982\u6211\u4eec\u521a\u624d\u4ecb\u7ecd\u7684 $uri \u548c $request_uri.\u5bf9\u53ea\u8bfb\u53d8\u91cf\u8fdb\u884c\u8d4b\u503c\u662f\u5e94\u5f53\u7edd\u5bf9\u907f\u514d\u7684\uff0c\u56e0\u4e3a\u4f1a\u6709\u610f\u60f3\u4e0d\u5230\u7684\u540e\u679c\uff0c\u6bd4\u5982\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$ curl&#8217;http:\/\/localhost:8080\/test?name=hello world&amp;class=9&#8242;<br>name: helloworld<br>class:9<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u6709\u95ee\u9898\u7684\u914d\u7f6e\u4f1a\u8ba9 Nginx \u5728\u542f\u52a8\u7684\u65f6\u5019\u62a5\u51fa\u4e00\u6761\u4ee4\u4eba\u532a\u5937\u6240\u601d\u7684\u9519\u8bef\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">[emerg] the duplicate &#8220;uri&#8221; variable in &#8230;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u5c1d\u8bd5\u6539\u5199\u53e6\u5916\u4e00\u4e9b\u53ea\u8bfb\u7684\u5185\u5efa\u53d8\u91cf\uff0c\u6bd4\u5982 $arg_XXX \u53d8\u91cf\uff0c\u5728\u67d0\u4e9b Nginx \u7684\u7248\u672c\u4e2d\u751a\u81f3\u53ef\u80fd\u5bfc\u81f4\u8fdb\u7a0b\u5d29\u6e83\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u4f7f\u7528\u7684\u5c31\u662f\u4e00\u95e8\u5fae\u578b\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u8bb8\u591a\u771f\u5b9e\u4e16\u754c\u91cc\u7684 Nginx\u914d\u7f6e\u6587\u4ef6\u5176\u5b9e\u5c31\u662f\u4e00\u4e2a\u4e00\u4e2a\u7684\u5c0f\u7a0b\u5e8f\u3002\u5f53\u7136\uff0c\u662f\u4e0d\u662f\u201c\u56fe\u7075\u5b8c\u5168\u7684\u201d\u6682\u4e14\u4e0d\u8bba\uff0c\u81f3\u5c11\u636e\u6211\u89c2\u5bdf\uff0c\u5b83\u5728\u8bbe\u8ba1\u4e0a\u53d7 Perl \u548c BourneShell \u8fd9\u4e24\u79cd\u8bed\u8a00\u7684\u5f71\u54cd\u5f88\u5927\u3002\u5728\u8fd9\u4e00\u70b9\u4e0a\uff0c\u76f8\u6bd4 Apache \u548c Lighttpd \u7b49\u5176\u4ed6 Web \u670d\u52a1\u5668\u7684\u914d\u7f6e\u8bb0\u6cd5\uff0c\u4e0d\u80fd\u4e0d\u8bf4\u7b97\u662fNginx \u7684\u4e00\u5927\u7279\u8272\u4e86\u3002\u65e2\u7136\u662f\u7f16\u7a0b\u8bed\u8a00\uff0c\u4e00\u822c\u4e5f\u5c31\u5c11\u4e0d\u4e86\u201c\u53d8\u91cf&hellip; <a class=\"more-link\" href=\"https:\/\/www.cygzs.net\/?p=57\">(more)<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_owldraft_subtitle":"","footnotes":""},"categories":[8,1],"tags":[],"class_list":["post-57","post","type-post","status-publish","format-standard","hentry","category-centos","category-it"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v17.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>nginx\u53d8\u91cf\u4f7f\u7528\u65b9\u6cd5\u8be6\u89e3 - \u7433\u6d77\u5bb6\u56ed<\/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.cygzs.net\/?p=57\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"nginx\u53d8\u91cf\u4f7f\u7528\u65b9\u6cd5\u8be6\u89e3 - \u7433\u6d77\u5bb6\u56ed\" \/>\n<meta property=\"og:description\" content=\"Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u4f7f\u7528\u7684\u5c31\u662f\u4e00\u95e8\u5fae\u578b\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u8bb8\u591a\u771f\u5b9e\u4e16\u754c\u91cc\u7684 Nginx\u914d\u7f6e\u6587\u4ef6\u5176\u5b9e\u5c31\u662f\u4e00\u4e2a\u4e00\u4e2a\u7684\u5c0f\u7a0b\u5e8f\u3002\u5f53\u7136\uff0c\u662f\u4e0d\u662f\u201c\u56fe\u7075\u5b8c\u5168\u7684\u201d\u6682\u4e14\u4e0d\u8bba\uff0c\u81f3\u5c11\u636e\u6211\u89c2\u5bdf\uff0c\u5b83\u5728\u8bbe\u8ba1\u4e0a\u53d7 Perl \u548c BourneShell \u8fd9\u4e24\u79cd\u8bed\u8a00\u7684\u5f71\u54cd\u5f88\u5927\u3002\u5728\u8fd9\u4e00\u70b9\u4e0a\uff0c\u76f8\u6bd4 Apache \u548c Lighttpd \u7b49\u5176\u4ed6 Web \u670d\u52a1\u5668\u7684\u914d\u7f6e\u8bb0\u6cd5\uff0c\u4e0d\u80fd\u4e0d\u8bf4\u7b97\u662fNginx \u7684\u4e00\u5927\u7279\u8272\u4e86\u3002\u65e2\u7136\u662f\u7f16\u7a0b\u8bed\u8a00\uff0c\u4e00\u822c\u4e5f\u5c31\u5c11\u4e0d\u4e86\u201c\u53d8\u91cf&hellip; (more)\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cygzs.net\/?p=57\" \/>\n<meta property=\"og:site_name\" content=\"\u7433\u6d77\u5bb6\u56ed\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-14T09:06:00+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"cy\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.cygzs.net\/#website\",\"url\":\"https:\/\/www.cygzs.net\/\",\"name\":\"\\u7433\\u6d77\\u5bb6\\u56ed\",\"description\":\"\\u4e00\\u4e2a\\u4e0d\\u52a1\\u6b63\\u4e1a\\u7684\\u8fd0\\u7ef4\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.cygzs.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.cygzs.net\/?p=57#webpage\",\"url\":\"https:\/\/www.cygzs.net\/?p=57\",\"name\":\"nginx\\u53d8\\u91cf\\u4f7f\\u7528\\u65b9\\u6cd5\\u8be6\\u89e3 - \\u7433\\u6d77\\u5bb6\\u56ed\",\"isPartOf\":{\"@id\":\"https:\/\/www.cygzs.net\/#website\"},\"datePublished\":\"2021-01-14T09:06:00+00:00\",\"dateModified\":\"2021-01-14T09:06:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.cygzs.net\/#\/schema\/person\/6db5162177413ff7529e7d15140c864a\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.cygzs.net\/?p=57#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.cygzs.net\/?p=57\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.cygzs.net\/?p=57#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\\u9996\\u9875\",\"item\":\"https:\/\/www.cygzs.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"nginx\\u53d8\\u91cf\\u4f7f\\u7528\\u65b9\\u6cd5\\u8be6\\u89e3\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.cygzs.net\/#\/schema\/person\/6db5162177413ff7529e7d15140c864a\",\"name\":\"cy\",\"sameAs\":[\"http:\/\/www.cygzs.net\"],\"url\":\"https:\/\/www.cygzs.net\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"nginx\u53d8\u91cf\u4f7f\u7528\u65b9\u6cd5\u8be6\u89e3 - \u7433\u6d77\u5bb6\u56ed","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.cygzs.net\/?p=57","og_locale":"zh_CN","og_type":"article","og_title":"nginx\u53d8\u91cf\u4f7f\u7528\u65b9\u6cd5\u8be6\u89e3 - \u7433\u6d77\u5bb6\u56ed","og_description":"Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u4f7f\u7528\u7684\u5c31\u662f\u4e00\u95e8\u5fae\u578b\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u8bb8\u591a\u771f\u5b9e\u4e16\u754c\u91cc\u7684 Nginx\u914d\u7f6e\u6587\u4ef6\u5176\u5b9e\u5c31\u662f\u4e00\u4e2a\u4e00\u4e2a\u7684\u5c0f\u7a0b\u5e8f\u3002\u5f53\u7136\uff0c\u662f\u4e0d\u662f\u201c\u56fe\u7075\u5b8c\u5168\u7684\u201d\u6682\u4e14\u4e0d\u8bba\uff0c\u81f3\u5c11\u636e\u6211\u89c2\u5bdf\uff0c\u5b83\u5728\u8bbe\u8ba1\u4e0a\u53d7 Perl \u548c BourneShell \u8fd9\u4e24\u79cd\u8bed\u8a00\u7684\u5f71\u54cd\u5f88\u5927\u3002\u5728\u8fd9\u4e00\u70b9\u4e0a\uff0c\u76f8\u6bd4 Apache \u548c Lighttpd \u7b49\u5176\u4ed6 Web \u670d\u52a1\u5668\u7684\u914d\u7f6e\u8bb0\u6cd5\uff0c\u4e0d\u80fd\u4e0d\u8bf4\u7b97\u662fNginx \u7684\u4e00\u5927\u7279\u8272\u4e86\u3002\u65e2\u7136\u662f\u7f16\u7a0b\u8bed\u8a00\uff0c\u4e00\u822c\u4e5f\u5c31\u5c11\u4e0d\u4e86\u201c\u53d8\u91cf&hellip; (more)","og_url":"https:\/\/www.cygzs.net\/?p=57","og_site_name":"\u7433\u6d77\u5bb6\u56ed","article_published_time":"2021-01-14T09:06:00+00:00","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"cy","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/www.cygzs.net\/#website","url":"https:\/\/www.cygzs.net\/","name":"\u7433\u6d77\u5bb6\u56ed","description":"\u4e00\u4e2a\u4e0d\u52a1\u6b63\u4e1a\u7684\u8fd0\u7ef4","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.cygzs.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"https:\/\/www.cygzs.net\/?p=57#webpage","url":"https:\/\/www.cygzs.net\/?p=57","name":"nginx\u53d8\u91cf\u4f7f\u7528\u65b9\u6cd5\u8be6\u89e3 - \u7433\u6d77\u5bb6\u56ed","isPartOf":{"@id":"https:\/\/www.cygzs.net\/#website"},"datePublished":"2021-01-14T09:06:00+00:00","dateModified":"2021-01-14T09:06:00+00:00","author":{"@id":"https:\/\/www.cygzs.net\/#\/schema\/person\/6db5162177413ff7529e7d15140c864a"},"breadcrumb":{"@id":"https:\/\/www.cygzs.net\/?p=57#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cygzs.net\/?p=57"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.cygzs.net\/?p=57#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.cygzs.net\/"},{"@type":"ListItem","position":2,"name":"nginx\u53d8\u91cf\u4f7f\u7528\u65b9\u6cd5\u8be6\u89e3"}]},{"@type":"Person","@id":"https:\/\/www.cygzs.net\/#\/schema\/person\/6db5162177413ff7529e7d15140c864a","name":"cy","sameAs":["http:\/\/www.cygzs.net"],"url":"https:\/\/www.cygzs.net\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/www.cygzs.net\/index.php?rest_route=\/wp\/v2\/posts\/57","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cygzs.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cygzs.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cygzs.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cygzs.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=57"}],"version-history":[{"count":1,"href":"https:\/\/www.cygzs.net\/index.php?rest_route=\/wp\/v2\/posts\/57\/revisions"}],"predecessor-version":[{"id":58,"href":"https:\/\/www.cygzs.net\/index.php?rest_route=\/wp\/v2\/posts\/57\/revisions\/58"}],"wp:attachment":[{"href":"https:\/\/www.cygzs.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cygzs.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cygzs.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}