{"id":707,"date":"2019-08-06T16:43:32","date_gmt":"2019-08-06T08:43:32","guid":{"rendered":"https:\/\/www.zhuyanbin.com\/?p=707"},"modified":"2019-08-06T16:44:25","modified_gmt":"2019-08-06T08:44:25","slug":"ngnix%e8%bd%ac%e5%8f%91%e8%a7%84%e5%88%99","status":"publish","type":"post","link":"https:\/\/www.yanbin888.com\/?p=707","title":{"rendered":"Ngnix\u8f6c\u53d1\u89c4\u5219"},"content":{"rendered":"\n<p>\u5728\u65e5\u5e38\u5f00\u53d1\u4f7f\u7528\u4e2d\u7ecf\u5e38\u4f1a\u4f7f\u7528nginx\u8fdb\u884c\u53cd\u5411\u4ee3\u7406\u6216\u8f6c\u53d1\uff0c\u56e0\u6b64\u8bb0\u5f55\u4e00\u4e0b\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"location-\u5339\u914d\u89c4\u5219\">location \u5339\u914d\u89c4\u5219<\/h2>\n\n\n\n<p>location [=|~|~*|^~] \/uri\/ { \u2026 }<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>\u6a21\u5f0f<\/td><td>\u542b\u4e49<\/td><\/tr><tr><td>location = \/uri<\/td><td>= \u8868\u793a\u7cbe\u786e\u5339\u914d\uff0c\u53ea\u6709\u5b8c\u5168\u5339\u914d\u4e0a\u624d\u80fd\u751f\u6548<\/td><\/tr><tr><td>location ^~ \/uri<\/td><td>^~ \u5f00\u5934\u5bf9URL\u8def\u5f84\u8fdb\u884c\u524d\u7f00\u5339\u914d\uff0c\u5e76\u4e14\u5728\u6b63\u5219\u4e4b\u524d<\/td><\/tr><tr><td>location ~ pattern<\/td><td>\u5f00\u5934\u8868\u793a\u533a\u5206\u5927\u5c0f\u5199\u7684\u6b63\u5219\u5339\u914d<\/td><\/tr><tr><td>location ~* pattern<\/td><td>\u5f00\u5934\u8868\u793a\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u7684\u6b63\u5219\u5339\u914d<\/td><\/tr><tr><td>location \/uri<\/td><td>\u4e0d\u5e26\u4efb\u4f55\u4fee\u9970\u7b26\uff0c\u4e5f\u8868\u793a\u524d\u7f00\u5339\u914d\uff0c\u4f46\u662f\u5728\u6b63\u5219\u5339\u914d\u4e4b\u540e<\/td><\/tr><tr><td>location \/<\/td><td>\u901a\u7528\u5339\u914d\uff0c\u4efb\u4f55\u672a\u5339\u914d\u5230\u5176\u5b83location\u7684\u8bf7\u6c42\u90fd\u4f1a\u5339\u914d\u5230\uff0c\u76f8\u5f53\u4e8eswitch\u4e2d\u7684default<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>\u524d\u7f00\u5339\u914d\u65f6\uff0cNginx \u4e0d\u5bf9 url \u505a\u7f16\u7801\uff0c\u56e0\u6b64\u8bf7\u6c42\u4e3a\u00a0<code>\/static\/20%\/aa<\/code>\uff0c\u53ef\u4ee5\u88ab\u89c4\u5219\u00a0<code>^~ \/static\/ \/aa<\/code>\u00a0\u5339\u914d\u5230\uff08\u6ce8\u610f\u662f\u7a7a\u683c\uff09<\/p>\n\n\n\n<p>\u591a\u4e2a location \u914d\u7f6e\u7684\u60c5\u51b5\u4e0b\u5339\u914d\u987a\u5e8f\u4e3a\uff08\u53c2\u8003\u8d44\u6599\u800c\u6765\uff0c\u8fd8\u672a\u5b9e\u9645\u9a8c\u8bc1\uff0c\u8bd5\u8bd5\u5c31\u77e5\u9053\u4e86\uff0c\u4e0d\u5fc5\u62d8\u6ce5\uff0c\u4ec5\u4f9b\u53c2\u8003\uff09:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u9996\u5148\u7cbe\u786e\u5339\u914d\u00a0<code>=<\/code><\/li><li>\u5176\u6b21\u524d\u7f00\u5339\u914d\u00a0<code>^~<\/code><\/li><li>\u5176\u6b21\u662f\u6309\u6587\u4ef6\u4e2d\u987a\u5e8f\u7684\u6b63\u5219\u5339\u914d<\/li><li>\u7136\u540e\u5339\u914d\u4e0d\u5e26\u4efb\u4f55\u4fee\u9970\u7684\u524d\u7f00\u5339\u914d<\/li><li>\u6700\u540e\u662f\u4ea4\u7ed9\u00a0<code>\/<\/code>\u00a0\u901a\u7528\u5339\u914d<\/li><li>\u5f53\u6709\u5339\u914d\u6210\u529f\u65f6\u5019\uff0c\u505c\u6b62\u5339\u914d\uff0c\u6309\u5f53\u524d\u5339\u914d\u89c4\u5219\u5904\u7406\u8bf7\u6c42<\/li><\/ul>\n\n\n\n<p><em>\u6ce8\u610f\uff1a\u524d\u7f00\u5339\u914d\uff0c\u5982\u679c\u6709\u5305\u542b\u5173\u7cfb\u65f6\uff0c\u6309\u6700\u5927\u5339\u914d\u539f\u5219\u8fdb\u884c\u5339\u914d\u3002\u6bd4\u5982\u5728\u524d\u7f00\u5339\u914d\uff1a<code>location \/dir01<\/code>\u4e0e\u00a0<code>location \/dir01\/dir02<\/code>\uff0c\u5982\u6709\u8bf7\u6c42\u00a0<code>http:\/\/localhost\/dir01\/dir02\/file<\/code>\u00a0\u5c06\u6700\u7ec8\u5339\u914d\u5230\u00a0<code>location \/dir01\/dir02<\/code><\/em><\/p>\n\n\n\n<p>\u4f8b\u5b50\uff0c\u6709\u5982\u4e0b\u5339\u914d\u89c4\u5219\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">location = \/ {\n   echo \"\u89c4\u5219A\";\n}\nlocation = \/login {\n   echo \"\u89c4\u5219B\";\n}\nlocation ^~ \/static\/ {\n   echo \"\u89c4\u5219C\";\n}\nlocation ^~ \/static\/files {\n    echo \"\u89c4\u5219X\";\n}\nlocation ~ \\.(gif|jpg|png|js|css)$ {\n   echo \"\u89c4\u5219D\";\n}\nlocation ~* \\.png$ {\n   echo \"\u89c4\u5219E\";\n}\nlocation \/img {\n    echo \"\u89c4\u5219Y\";\n}\nlocation \/ {\n   echo \"\u89c4\u5219F\";\n}<\/pre>\n\n\n\n<p>\u90a3\u4e48\u4ea7\u751f\u7684\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u8bbf\u95ee\u6839\u76ee\u5f55\u00a0<code>\/<\/code>\uff0c\u6bd4\u5982\u00a0<code>http:\/\/localhost\/<\/code>\u00a0\u5c06\u5339\u914d\u00a0<code>\u89c4\u5219A<\/code><\/li><li>\u8bbf\u95ee\u00a0<code>http:\/\/localhost\/login<\/code>\u00a0\u5c06\u5339\u914d\u00a0<code>\u89c4\u5219B<\/code>\uff0c<code>http:\/\/localhost\/register<\/code>\u00a0\u5219\u5339\u914d\u00a0<code>\u89c4\u5219F<\/code><\/li><li>\u8bbf\u95ee\u00a0<code>http:\/\/localhost\/static\/a.html<\/code>\u00a0\u5c06\u5339\u914d\u00a0<code>\u89c4\u5219C<\/code><\/li><li>\u8bbf\u95ee\u00a0<code>http:\/\/localhost\/static\/files\/a.exe<\/code>\u00a0\u5c06\u5339\u914d\u00a0<code>\u89c4\u5219X<\/code>\uff0c\u867d\u7136\u00a0<code>\u89c4\u5219C<\/code>\u00a0\u4e5f\u80fd\u5339\u914d\u5230\uff0c\u4f46\u56e0\u4e3a\u6700\u5927\u5339\u914d\u539f\u5219\uff0c\u6700\u7ec8\u9009\u4e2d\u4e86\u00a0<code>\u89c4\u5219X<\/code>\u3002\u4f60\u53ef\u4ee5\u6d4b\u8bd5\u4e0b\uff0c\u53bb\u6389\u89c4\u5219 X \uff0c\u5219\u5f53\u524d URL \u4f1a\u5339\u914d\u4e0a\u00a0<code>\u89c4\u5219C<\/code>\u3002<\/li><li>\u8bbf\u95ee\u00a0<code>http:\/\/localhost\/a.gif<\/code>,\u00a0<code>http:\/\/localhost\/b.jpg<\/code>\u00a0\u5c06\u5339\u914d\u00a0<code>\u89c4\u5219D<\/code>\u00a0\u548c\u00a0<code>\u89c4\u5219 E<\/code>\u00a0\uff0c\u4f46\u662f\u00a0<code>\u89c4\u5219 D<\/code>\u00a0\u987a\u5e8f\u4f18\u5148\uff0c<code>\u89c4\u5219 E<\/code>\u00a0\u4e0d\u8d77\u4f5c\u7528\uff0c\u800c\u00a0<code>http:\/\/localhost\/static\/c.png<\/code>\u00a0\u5219\u4f18\u5148\u5339\u914d\u5230\u00a0<code>\u89c4\u5219 C<\/code><\/li><li>\u8bbf\u95ee\u00a0<code>http:\/\/localhost\/a.PNG<\/code>\u00a0\u5219\u5339\u914d\u00a0<code>\u89c4\u5219 E<\/code>\u00a0\uff0c\u800c\u4e0d\u4f1a\u5339\u914d\u00a0<code>\u89c4\u5219 D<\/code>\u00a0\uff0c\u56e0\u4e3a\u00a0<code>\u89c4\u5219 E<\/code>\u00a0\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u3002<\/li><li>\u8bbf\u95ee\u00a0<code>http:\/\/localhost\/img\/a.gif<\/code>\u00a0\u4f1a\u5339\u914d\u4e0a\u00a0<code>\u89c4\u5219D<\/code>,\u867d\u7136\u00a0<code>\u89c4\u5219Y<\/code>\u00a0\u4e5f\u53ef\u4ee5\u5339\u914d\u4e0a\uff0c\u4f46\u662f\u56e0\u4e3a\u6b63\u5219\u5339\u914d\u4f18\u5148\uff0c\u800c\u5ffd\u7565\u4e86\u00a0<code>\u89c4\u5219Y<\/code>\u3002<\/li><li>\u8bbf\u95ee\u00a0<code>http:\/\/localhost\/img\/a.tiff<\/code>\u00a0\u4f1a\u5339\u914d\u4e0a\u00a0<code>\u89c4\u5219Y<\/code>\u3002<\/li><\/ul>\n\n\n\n<p>\u8bbf\u95ee\u00a0<code>http:\/\/localhost\/category\/id\/1111<\/code>\u00a0\u5219\u6700\u7ec8\u5339\u914d\u5230\u89c4\u5219 F \uff0c\u56e0\u4e3a\u4ee5\u4e0a\u89c4\u5219\u90fd\u4e0d\u5339\u914d\uff0c\u8fd9\u4e2a\u65f6\u5019\u5e94\u8be5\u662f Nginx \u8f6c\u53d1\u8bf7\u6c42\u7ed9\u540e\u7aef\u5e94\u7528\u670d\u52a1\u5668\uff0c\u6bd4\u5982 FastCGI\uff08php\uff09\uff0ctomcat\uff08jsp\uff09\uff0cNginx \u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u5b58\u5728\u3002<\/p>\n\n\n\n<p>Link: <a href=\"https:\/\/moonbingbing.gitbooks.io\/openresty-best-practices\/ngx\/nginx_local_pcre.html\">https:\/\/moonbingbing.gitbooks.io\/openresty-best-practices\/ngx\/nginx_local_pcre.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u65e5\u5e38\u5f00\u53d1\u4f7f\u7528\u4e2d\u7ecf\u5e38\u4f1a\u4f7f\u7528nginx\u8fdb\u884c\u53cd\u5411\u4ee3\u7406\u6216\u8f6c\u53d1\uff0c\u56e0\u6b64\u8bb0\u5f55\u4e00\u4e0b\uff1a location \u5339\u914d\u89c4\u5219 locat <span class=\"ellipsis\">&hellip;<\/span> <span class=\"more-link-wrap\"><a href=\"https:\/\/www.yanbin888.com\/?p=707\" class=\"more-link\"><span>Read More &rarr;<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[21],"class_list":["post-707","post","type-post","status-publish","format-standard","hentry","category-nginx","tag-nginx"],"_links":{"self":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=707"}],"version-history":[{"count":2,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/707\/revisions"}],"predecessor-version":[{"id":709,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/707\/revisions\/709"}],"wp:attachment":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}