{"id":1057,"date":"2021-06-29T12:19:12","date_gmt":"2021-06-29T12:19:12","guid":{"rendered":"http:\/\/www.liutianfeng.com\/?p=1057"},"modified":"2023-02-08T08:43:57","modified_gmt":"2023-02-08T08:43:57","slug":"nginx-location","status":"publish","type":"post","link":"https:\/\/www.liutianfeng.com\/?p=1057","title":{"rendered":"Nginx location"},"content":{"rendered":"<p>\u53c2\u8003<\/p>\n<p>https:\/\/www.cnblogs.com\/ronghua\/p\/13043466.html<\/p>\n<p>\u8bed\u6cd5\u89c4\u5219\uff1a location [=|~|~*|^~] \/uri\/ {\u2026 }<br \/>\n\u9996\u5148\u5339\u914d =\uff0c\u5176\u6b21\u5339\u914d^~\uff0c\u5176\u6b21\u662f\u6309\u6587\u4ef6\u4e2d\u6b63\u5219\u7684\u5148\u540e\u987a\u5e8f\u5339\u914d\uff0c\u5f53\u6709\u5339\u914d\u6210\u529f\u65f6\u5019\uff0c\u505c\u6b62\u5339\u914d\u5e76\u6309\u5f53\u524d\u5339\u914d\u89c4\u5219\u5904\u7406\u8bf7\u6c42\uff0c\u5176\u4ed6\u6b63\u5219\u65e0\u6cd5\u5339\u914d\u5219\u6700\u540e\u4ea4\u7531\/\u901a\u914d\u3002<\/p>\n<h2><strong>Exp1\uff1a\u5bf9\u6bd4=\uff0c^~\uff0c~\uff0c~*\u54ea\u4e2a\u4f18\u5148\u7ea7\u6700\u9ad8<\/strong><\/h2>\n<pre class=\"pure-highlightjs\"><code class=\"\"># cat lius.conf\nserver {\n    listen       80;\n    server_name  lius.com;\n    location ^~ \/lius {\n        default_type 'text\/plain';\n        return 200 \"^~ \/lius\\n\";\n    }\n    location ~ \/lius {\n        default_type 'text\/plain';\n        return 200 \"~ \/lius\\n\";\n    }\n    location ~* \/lius {\n        default_type 'text\/plain';\n        return 200 \"~* \/lius\\n\";\n    }\n    location = \/lius {\n        default_type 'text\/plain';\n        return 200 \"= \/lius\\n\";\n    }\n}\n# curl lius.com\/lius   # hosts\u52ab\u6301lius.com\n= \/lius<\/code><\/pre>\n<p>\u7ed3\u8bba\uff1a\u8bf4\u660e=\u7684\u4f18\u5148\u7ea7\u662f\u6700\u9ad8\u7684\u3010\u5fc5\u987b\u662f\u5b8c\u5168\u5339\u914d\u3011\uff0c\u4e0e\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u4f4d\u7f6e\u65e0\u5173\uff1b<\/p>\n<h2><strong>Exp2\uff1a\u5bf9\u6bd4^~\uff0c~\uff0c~*\u54ea\u4e2a\u4f18\u5148\u7ea7\u6700\u9ad8\uff0c\u540c\u4e3a^~\u7684\u5339\u914d\u539f\u5219\uff1f<\/strong><\/h2>\n<pre class=\"pure-highlightjs\"><code class=\"\">server {\n    listen       80;\n    server_name  lius.com;\n    location ^~ \/liu {\n        default_type 'text\/plain';\n        return 200 \"^~ \/liu\\n\";\n    }\n    location ~ \/liusddd {\n        default_type 'text\/plain';\n        return 200 \"~ \/liusddd\\n\";\n    }\n    location ~* \/liusddd {\n        default_type 'text\/plain';\n        return 200 \"~* \/liusddd\\n\";\n    }\n    location ^~ \/lius {\n        default_type 'text\/plain';\n        return 200 \"^~ \/lius\\n\";\n    }\n}\n# curl lius.com\/liusddd\n^~ \/lius<\/code><\/pre>\n<p>\u7ed3\u8bba\uff1a<\/p>\n<p>1\u3001\u8bf4\u660e^~\u7684\u4f18\u5148\u7ea7\u4ec5\u6b21\u4e8e=\uff0c~*\uff0c~\u5373\u4f7f\u66f4\u52a0\u5339\u914d\uff0c\u4e5f\u4f18\u5148\u7ecf\u8fc7^~\u7684\u5339\u914d\uff1b<\/p>\n<p>2\u3001\u540c\u7ea7\u7684^~\u5339\u914d\u539f\u5219\u9075\u5faa\u3010\u66f4\u7cbe\u51c6\u5730\u5339\u914d\u3011\uff0cliusddd\u5339\u914dlius\uff0c\u81ea\u7136\u5339\u914dliu\uff0c\u4f46lius\u66f4\u7cbe\u51c6\u5730\u5339\u914d\u3010\u4e0b\u9762\u4f8b\u5b50\u6392\u9664\u987a\u5e8f\u5f71\u54cd\u3011\uff1b<\/p>\n<h2><strong>Exp3\uff1a\u540c\u4e3a^~\uff0c\u987a\u5e8f\u662f\u5426\u5f71\u54cd\uff1f<\/strong><\/h2>\n<pre class=\"pure-highlightjs\"><code class=\"\"># cat lius.conf \nserver {\n    listen       80;\n    server_name  lius.com;\n\n    location ^~ \/liu {\n        default_type 'text\/plain';\n        return 200 \"^~ \/liu\\n\";\n    }\n\n    location ^~ \/lius {\n        default_type 'text\/plain';\n        return 200 \"^~ \/lius\\n\";\n    }\n}\n# curl lius.com\/liusddd\n^~ \/lius\n# curl lius.com\/liu\n^~ \/liu\n# cat lius.conf # \u4fee\u6539\u987a\u5e8f\nserver {\n    listen       80;\n    server_name  lius.com;\n\n    location ^~ \/lius {\n        default_type 'text\/plain';\n        return 200 \"^~ \/lius\\n\";\n    }\n\n    location ^~ \/liu {\n        default_type 'text\/plain';\n        return 200 \"^~ \/liu\\n\";\n    }\n}\n# curl lius.com\/liusddd\n^~ \/lius\n# curl lius.com\/liu\n^~ \/liu\n<\/code><\/pre>\n<p>\u7ed3\u8bba\uff1a\u540c\u4e3a~^\uff0c\u5339\u914d\u4e0e\u987a\u5e8f\u65e0\u5173\uff0c\u53ea\u9075\u5faa\u3010\u66f4\u7cbe\u51c6\u5730\u5339\u914d\u3011\u539f\u5219\uff1b<\/p>\n<h2>location\u4e0a\u4e0b\u6587\u3010\u5e26\u4e0d\u5e26\/\u3011\u914d\u7f6e\u8bf4\u660e<\/h2>\n<p>\u53c2\u8003\uff1ahttps:\/\/www.jb51.net\/article\/244331.htm<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">https:\/\/www.liutianfeng.com\/api\/upload --&gt; localhost:8080\/upload\n\nlocation \/api\/ {\n    proxy_pass http:\/\/localhost:8080\/;\n}<\/code><\/pre>\n<p>proxy_pass\u672b\u5c3e\u5e26\/, location\u90e8\u5206\u5c31\u4e0d\u5411\u540e\u7aef\u4f20\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">URL: www.liutianfeng.com\/api\/upload\nProxy_Path: http:\/\/localhost:8080\/\nURI = \/api\/upload\nLocation = \/api\/\nProxy_Uri = URI - Location = upload\nDefinite_Proxy_Url = Proxy_Path + Proxy_Uri  = http:\/\/localhost:8080\/upload<\/code><\/pre>\n<p>proxy_pass\u672b\u5c3e\u4e0d\u5e26\/, location\u90e8\u5206\u5c31\u5411\u540e\u7aef\u4f20\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">URL: www.liutianfeng.com\/api\/upload\nProxy_Path: http:\/\/localhost:8080\nURI = \/api\/upload\nLocation = \/api\/\nProxy_Uri = URI = \/api\/upload\nDefinite_Proxy_Url = Proxy_Path + Proxy_Uri = http:\/\/localhost:8080\/api\/upload<\/code><\/pre>\n<p>\u5bb9\u6613\u51fa\u95ee\u9898\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">URL: www.liutianfeng.com\/api\/upload\nProxy_Path: http:\/\/localhost:8080\/server\/\nURI = \/api\/upload\nLocation = \/api\nProxy_Uri = URI - Location = \/upload\nDefinite_Proxy_Url = Proxy_Path + Proxy_Uri = http:\/\/localhost:8080\/server\/\/upload  \/\/ \u8fd9\u91cc\u662f\u591a\u51fa\u4e86\u4e00\u4e2a\/, \u4e00\u822c\u662f\u6709\u95ee\u9898\u7684<\/code><\/pre>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/www.liutianfeng.com\">liutianfeng.com<\/a> &raquo; <a href=\"https:\/\/www.liutianfeng.com\/?p=1057\">Nginx location<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u53c2\u8003 https:\/\/www.cnblogs.com\/ronghua\/p\/13043466.html \u8bed\u6cd5\u89c4\u5219 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[50],"tags":[],"_links":{"self":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/1057"}],"collection":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1057"}],"version-history":[{"count":4,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/1057\/revisions"}],"predecessor-version":[{"id":1582,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/1057\/revisions\/1582"}],"wp:attachment":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}