{"id":880,"date":"2018-07-04T22:04:22","date_gmt":"2018-07-04T14:04:22","guid":{"rendered":"http:\/\/www.sulabs.net\/?p=880"},"modified":"2020-08-28T18:23:32","modified_gmt":"2020-08-28T10:23:32","slug":"nginx%e9%85%8d%e7%bd%ae%e4%b8%adlocation%e7%9a%84%e5%8c%b9%e9%85%8d%e8%a7%84%e5%88%99","status":"publish","type":"post","link":"https:\/\/www.sulabs.net\/?p=880","title":{"rendered":"Nginx\u914d\u7f6e\u4e2dLocation\u7684\u5339\u914d\u89c4\u5219"},"content":{"rendered":"<p>\u8f6c\u81ea https:\/\/blog.csdn.net\/abel004\/article\/details\/77838107<br \/>\n\u4e0d\u9519\u7684\u8d44\u6599\uff0c\u7559\u4e00\u4efd\u4ee5\u5907\u4e0d\u65f6\u4e4b\u9700<\/p>\n<p>Location\u5339\u914d\u7684url\u7684\u8bed\u6cd5\u89c4\u5219\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>location [=|~|~*|^~] \/uri\/ { \u2026 }<\/pre>\n<\/div>\n<p>=\u3000\u3000\u8868\u793a\u7cbe\u786e\u5339\u914d<br \/>\n<!--more--><\/p>\n<p>~\u3000\u3000\u8868\u793a\u533a\u5206\u5927\u5c0f\u5199\u7684\u6b63\u5219\u5339\u914d<\/p>\n<p>^~\u3000\u8868\u793a\u4ee5\u67d0\u4e2a\u5e38\u89c4\u5b57\u7b26\u4e32\u5f00\u5934\u7684url\u5373\u53ef\uff1b<\/p>\n<p>~*\u3000\u8868\u793a\u4e0d\u533a\u5206\u5927\u6d88\u606f\u7684\u6b63\u5219\u5339\u914d<\/p>\n<p>!~\uff08*!~\uff09\u8868\u793a\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u4e0d\u5339\u914d\u7684\u6b63\u5219<\/p>\n<p>\/\u3000\u3000\u901a\u914d\u7b26\uff0c\u4efb\u4f55\u8bf7\u6c42\u90fd\u80fd\u5339\u914d\u5230\u8fd9\u4e2alocation\uff0c\u5982\u679c\u6709\u4efb\u4f55\u5176\u4ed6location\u53ef\u4ee5\u5339\u914d\uff0c\u5219\u4f1a\u8986\u76d6\u8be5location<\/p>\n<p>\u5339\u914d\u987a\u5e8f\uff1a<\/p>\n<p>1\uff09\u5148\u5339\u914d\u666e\u901aurl\uff0c\u5728\u5339\u914d\u6b63\u5219<\/p>\n<p>2\uff09\u201c\u666e\u901a&nbsp;location&nbsp;\u201d\u7684\u5339\u914d\u89c4\u5219\u662f\u201c\u6700\u5927\u524d\u7f00\u201d\uff0c\u56e0\u6b64\u201c\u666e\u901a&nbsp;location&nbsp;\u201d\u7684\u786e\u4e0e&nbsp;location&nbsp;\u7f16\u8f91\u987a\u5e8f\u65e0\u5173\uff1b<\/p>\n<p>3\uff09location\u7684\u6267\u884c\u903b\u8f91\u57fa\u672c\u4e0a\u8ddf\u987a\u5e8f\u6ca1\u6709\u5173\u7cfb\uff1b\u4f46\u662f\u9488\u5bf9\u6b63\u5219\u5339\u914d\u7684\u65b9\u5f0f\uff0c\u5339\u914d\u4e0a\u7b2c\u4e00\u4e2aurl\uff0c\u5c31\u4e0d\u5728\u7ee7\u7eed\u5339\u914d\u540e\u9762\u7684url\uff1b<\/p>\n<p>\u8fd9\u79cd\u60c5\u51b5\uff0c\u5982\u679c\u5339\u914d\u4e0a\u666e\u901alocaltion\uff0c\u6ca1\u6709\u6b63\u5219\u5339\u914d\uff0c\u5219\u4f7f\u7528\u666e\u901a\u5339\u914d\uff1b\u5982\u679c\u65e2\u6709\u666e\u901alocation\u7684\u6700\u5927\u524d\u7f00\u5339\u914d\uff0c\u4e5f\u6709\u6b63\u5219\u5339\u914d\uff0c\u5219\u6b63\u5219\u5339\u914d\u8986\u76d6\u6700\u5927\u524d\u7f00\u5339\u914d\u3002<\/p>\n<p>4\uff09\u5339\u914d\u5b8c\u201c\u666e\u901a&nbsp;location&nbsp;\u201d\u540e\uff0c\u6709\u7684\u65f6\u5019\u9700\u8981\u7ee7\u7eed\u5339\u914d\u201c\u6b63\u5219&nbsp;location&nbsp;\u201d\uff0c\u6709\u7684\u65f6\u5019\u5219\u4e0d\u9700\u8981\u7ee7\u7eed\u5339\u914d\u201c\u6b63\u5219&nbsp;location&nbsp;\u201d\u3002<\/p>\n<p>\u4e24\u79cd\u60c5\u51b5\u4e0b\uff0c\u4e0d\u9700\u8981\u7ee7\u7eed\u5339\u914d\u6b63\u5219&nbsp;location&nbsp;\uff1a(1) \u5f53\u666e\u901a&nbsp;location&nbsp;\u524d\u9762\u6307\u5b9a\u4e86\u201c&nbsp;^~&nbsp;\u201d\uff0c\u7279\u522b\u544a\u8bc9&nbsp;Nginx&nbsp;\u672c\u6761\u666e\u901a&nbsp;location&nbsp;\u4e00\u65e6\u5339\u914d\u4e0a\uff0c\u5219\u4e0d\u9700\u8981\u7ee7\u7eed\u6b63\u5219\u5339\u914d\uff1b(2) \u5f53\u666e\u901alocation&nbsp;\u6070\u597d\u4e25\u683c\u5339\u914d\u4e0a\uff0c\u4e0d\u662f\u6700\u5927\u524d\u7f00\u5339\u914d\uff0c\u5219\u4e0d\u518d\u7ee7\u7eed\u5339\u914d\u6b63\u5219\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>location  = \/ {\r\n  # matches the query \/ only.\r\n  [ configuration A ] \r\n}\r\nlocation  \/ {\r\n  # matches any query, since all queries begin with \/, but regular\r\n  # expressions and any longer conventional blocks will be\r\n  # matched first.\r\n  [ configuration B ] \r\n}\r\nlocation \/documents\/ {\r\n  # matches any query beginning with \/documents\/ and continues searching,\r\n  # so regular expressions will be checked. This will be matched only if\r\n  # regular expressions don\u2018t find a match.\r\n  [ configuration C ] \r\n}\r\nlocation ^~ \/images\/ {\r\n  # matches any query beginning with \/images\/ and halts searching,\r\n  # so regular expressions will not be checked.\r\n  [ configuration D ] \r\n}\r\nlocation ~* \\.(gif|jpg|jpeg)$ {\r\n  # matches any request ending in gif, jpg, or jpeg. However, all\r\n  # requests to the \/images\/ directory will be handled by\r\n  # Configuration D.   \r\n  [ configuration E ] \r\n}<\/pre>\n<\/div>\n<p>\u8bf7\u6c42\u793a\u4f8b\uff0c\u5339\u914d\u7684Location:<\/p>\n<ul>\n<li>\/ -&gt; configuration A<\/li>\n<li>\/index.html -&gt; configuration B<\/li>\n<li>\/documents\/document.html -&gt; configuration C<\/li>\n<li>\/images\/1.gif -&gt; configuration D<\/li>\n<li>\/documents\/1.jpg -&gt; configuration E<\/li>\n<\/ul>\n<div>----------------------------------------------------------------------<\/div>\n<div>\n<p>\u5339\u914d\u7684\u4f18\u5148\u7ea7\u5982\u4e0b<\/p>\n<p>1\u3001\u5982\u679c\u67e5\u8be2\u7cbe\u786e\u7684\u547d\u4e2d\u4e86\u4e00\u4e2a\u4f7f\u7528=\u524d\u7f00\u7684location\uff0c\u90a3\u4e2a\u5b83\u5c06\u88ab\u4f7f\u7528\uff0c\u5e76\u7ed3\u675f\u5339\u914d<\/p>\n<p>2\u3001\u5728\u5269\u4e0b\u666e\u901a\u5b57\u7b26\u4e32\u4e2d\uff0c\u5c06\u6309\u7167\u6700\u5927\u524d\u7f00\u5339\u914d\u7684\u539f\u5219\u8fdb\u884c\u5339\u914d\uff0c\u5c06\u7ed3\u679c\u6700\u540e\u5019\u9009\u7ed3\u679c\uff0c\u5982\u679c\u6700\u7ec8\u547d\u4e2d\u7684\u7ed3\u679c\u4f7f\u7528\u4e86^~\u524d\u7f00\u8868\u793a\u6216\u8005\u5b83\u662f\u4e00\u4e2a\u5b8c\u5168\u5339\u914d\uff0c\u90a3\u4e48\u5b83\u5c06\u88ab\u4f7f\u7528\uff0c\u5e76\u7ed3\u675f\u5339\u914d<\/p>\n<p>3\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u65f6\uff0c\u6309\u7167\u6b63\u5219\u8868\u8fbe\u5f0f\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u51fa\u73b0\u7684\u987a\u5e8f\uff0c\u5e76\u4e14\u53ea\u6709\u5339\u914d\u5230\u4e86\u4e00\u6761\u6b63\u5219local\uff0c\u5c31\u4e0d\u5728\u5339\u914d\u4e0b\u9762\u7684local\u4e86<\/p>\n<p>4\u3001\u5982\u679c\u6b65\u9aa43\u547d\u4e2d\u4e86\u4e00\u4e2a\u5339\u914d\uff0c\u90a3\u4e2a\u5b83\u5c06\u88ab\u4f7f\u7528\uff0c\u5426\u5219\u5c06\u4f7f\u7528\u6b65\u9aa42\u7684\u5019\u9009\u7ed3\u679c<\/p>\n<p>\uff08\u666e\u901a\u5b57\u7b26\u4e32\u548c\u6b63\u5219\u5b57\u7b26\u4e32\u7684\u533a\u522b ~\u548c~*\u524d\u7f00\u8868\u793alocation\u662f\u6b63\u5219\u5b57\u7b26\u4e32\uff0c\u5176\u4ed6\u524d\u7f00\u548c\u65e0\u524d\u7f00\u8868\u793alocation\u662f\u666e\u901a\u5b57\u7b26\u4e32\uff09<\/p>\n<p><span style=\"font-size: 1rem;\">----------------------------------------------------------------------------------------------------------------------------------------<\/span><\/p>\n<\/div>\n<div>\n<p>\u8bed\u6cd5\u89c4\u5219\uff1a location [=|~|~*|^~] \/uri\/ { \u2026 }<br \/>\n= \u5f00\u5934\u8868\u793a\u7cbe\u786e\u5339\u914d<br \/>\n^~ \u5f00\u5934\u8868\u793auri\u4ee5\u67d0\u4e2a\u5e38\u89c4\u5b57\u7b26\u4e32\u5f00\u5934\uff0c\u7406\u89e3\u4e3a\u5339\u914d url\u8def\u5f84\u5373\u53ef\u3002nginx\u4e0d\u5bf9url\u505a\u7f16\u7801\uff0c\u56e0\u6b64\u8bf7\u6c42\u4e3a\/static\/20%\/aa\uff0c\u53ef\u4ee5\u88ab\u89c4\u5219^~ \/static\/ \/aa\u5339\u914d\u5230\uff08\u6ce8\u610f\u662f\u7a7a\u683c\uff09\u3002<br \/>\n~ \u5f00\u5934\u8868\u793a\u533a\u5206\u5927\u5c0f\u5199\u7684\u6b63\u5219\u5339\u914d<br \/>\n~*&nbsp;&nbsp;\u5f00\u5934\u8868\u793a\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u7684\u6b63\u5219\u5339\u914d<br \/>\n!~\u548c!~*\u5206\u522b\u4e3a\u533a\u5206\u5927\u5c0f\u5199\u4e0d\u5339\u914d\u53ca\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u4e0d\u5339\u914d \u7684\u6b63\u5219<br \/>\n\/ \u901a\u7528\u5339\u914d\uff0c\u4efb\u4f55\u8bf7\u6c42\u90fd\u4f1a\u5339\u914d\u5230\u3002<br \/>\n\u591a\u4e2alocation\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:<br \/>\n\u9996\u5148\u5339\u914d =\uff0c\u5176\u6b21\u5339\u914d^~, \u5176\u6b21\u662f\u6309\u6587\u4ef6\u4e2d\u987a\u5e8f\u7684\u6b63\u5219\u5339\u914d\uff0c\u6700\u540e\u662f\u4ea4\u7ed9 \/ \u901a\u7528\u5339\u914d\u3002\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\u3002<br \/>\n\u4f8b\u5b50\uff0c\u6709\u5982\u4e0b\u5339\u914d\u89c4\u5219\uff1a<br \/>\nlocation = \/ {<br \/>\n&nbsp;&nbsp;&nbsp;#\u89c4\u5219A<br \/>\n}<br \/>\nlocation = \/login {<br \/>\n&nbsp;&nbsp;&nbsp;#\u89c4\u5219B<br \/>\n}<br \/>\nlocation ^~ \/static\/ {<br \/>\n&nbsp;&nbsp;&nbsp;#\u89c4\u5219C<br \/>\n}<br \/>\nlocation ~ \\.(gif|jpg|png|<a class=\"replace_word\" title=\"JavaScript\u77e5\u8bc6\u5e93\" href=\"http:\/\/lib.csdn.net\/base\/javascript\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">js<\/a>|css)$ {<br \/>\n&nbsp;&nbsp;&nbsp;#\u89c4\u5219D<br \/>\n}<br \/>\nlocation ~* \\.png$ {<br \/>\n&nbsp;&nbsp;&nbsp;#\u89c4\u5219E<br \/>\n}<br \/>\nlocation !~ \\.xhtml$ {<br \/>\n&nbsp;&nbsp;&nbsp;#\u89c4\u5219F<br \/>\n}<br \/>\nlocation !~* \\.xhtml$ {<br \/>\n&nbsp;&nbsp;&nbsp;#\u89c4\u5219G<br \/>\n}<br \/>\nlocation \/ {<br \/>\n&nbsp;&nbsp;&nbsp;#\u89c4\u5219H<br \/>\n}<br \/>\n\u90a3\u4e48\u4ea7\u751f\u7684\u6548\u679c\u5982\u4e0b\uff1a<br \/>\n\u8bbf\u95ee\u6839\u76ee\u5f55\/\uff0c \u6bd4\u5982<a href=\"http:\/\/localhost\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/localhost\/<\/a>&nbsp;\u5c06\u5339\u914d\u89c4\u5219A<br \/>\n\u8bbf\u95ee&nbsp;<a href=\"http:\/\/localhost\/login\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/localhost\/login<\/a>&nbsp;\u5c06\u5339\u914d\u89c4\u5219B\uff0c<a href=\"http:\/\/localhost\/register\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/localhost\/register<\/a>&nbsp;\u5219\u5339\u914d\u89c4\u5219H<br \/>\n\u8bbf\u95ee&nbsp;<a href=\"http:\/\/localhost\/static\/a.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/localhost\/static\/a.html<\/a>&nbsp;\u5c06\u5339\u914d\u89c4\u5219C<br \/>\n\u8bbf\u95ee&nbsp;<a href=\"http:\/\/localhost\/a.gif\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/localhost\/a.gif<\/a>,&nbsp;<a href=\"http:\/\/localhost\/b.jpg\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/localhost\/b.jpg<\/a>&nbsp;\u5c06\u5339\u914d\u89c4\u5219D\u548c\u89c4\u5219E\uff0c\u4f46\u662f\u89c4\u5219D\u987a\u5e8f\u4f18\u5148\uff0c\u89c4\u5219E\u4e0d\u8d77\u4f5c\u7528\uff0c\u800c&nbsp;<a href=\"http:\/\/localhost\/static\/c.png\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/localhost\/static\/c.png<\/a>&nbsp;\u5219\u4f18\u5148\u5339\u914d\u5230\u89c4\u5219C<br \/>\n\u8bbf\u95ee&nbsp;<a href=\"http:\/\/localhost\/a.PNG\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/localhost\/a.PNG<\/a>&nbsp;\u5219\u5339\u914d\u89c4\u5219E\uff0c\u800c\u4e0d\u4f1a\u5339\u914d\u89c4\u5219D\uff0c\u56e0\u4e3a\u89c4\u5219E\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u3002<br \/>\n\u8bbf\u95ee&nbsp;<a href=\"http:\/\/localhost\/a.xhtml\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/localhost\/a.xhtml<\/a>&nbsp;\u4e0d\u4f1a\u5339\u914d\u89c4\u5219F\u548c\u89c4\u5219G\uff0c<a href=\"http:\/\/localhost\/a.XHTML\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/localhost\/a.XHTML<\/a>\u4e0d\u4f1a\u5339\u914d\u89c4\u5219G\uff0c\u56e0\u4e3a\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u3002\u89c4\u5219F\uff0c\u89c4\u5219G\u5c5e\u4e8e\u6392\u9664\u6cd5\uff0c\u7b26\u5408\u5339\u914d\u89c4\u5219\u4f46\u662f\u4e0d\u4f1a\u5339\u914d\u5230\uff0c\u6240\u4ee5\u60f3\u60f3\u770b\u5b9e\u9645\u5e94\u7528\u4e2d\u54ea\u91cc\u4f1a\u7528\u5230\u3002<br \/>\n\u8bbf\u95ee&nbsp;<a href=\"http:\/\/localhost\/category\/id\/1111\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/localhost\/category\/id\/1111<\/a>&nbsp;\u5219\u6700\u7ec8\u5339\u914d\u5230\u89c4\u5219H\uff0c\u56e0\u4e3a\u4ee5\u4e0a\u89c4\u5219\u90fd\u4e0d\u5339\u914d\uff0c\u8fd9\u4e2a\u65f6\u5019\u5e94\u8be5\u662fnginx\u8f6c\u53d1\u8bf7\u6c42\u7ed9\u540e\u7aef\u5e94\u7528\u670d\u52a1\u5668\uff0c\u6bd4\u5982FastCGI\uff08<a class=\"replace_word\" title=\"PHP\u77e5\u8bc6\u5e93\" href=\"http:\/\/lib.csdn.net\/base\/php\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">PHP<\/a>\uff09\uff0ctomcat\uff08jsp\uff09\uff0cnginx\u4f5c\u4e3a\u65b9\u5411\u4ee3\u7406\u670d\u52a1\u5668\u5b58\u5728\u3002<\/p>\n<p>\u6240\u4ee5\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u4e2a\u4eba\u89c9\u5f97\u81f3\u5c11\u6709\u4e09\u4e2a\u5339\u914d\u89c4\u5219\u5b9a\u4e49\uff0c\u5982\u4e0b\uff1a<br \/>\n#\u76f4\u63a5\u5339\u914d\u7f51\u7ad9\u6839\uff0c\u901a\u8fc7\u57df\u540d\u8bbf\u95ee\u7f51\u7ad9\u9996\u9875\u6bd4\u8f83\u9891\u7e41\uff0c\u4f7f\u7528\u8fd9\u4e2a\u4f1a\u52a0\u901f\u5904\u7406\uff0c\u5b98\u7f51\u5982\u662f\u8bf4\u3002<br \/>\n#\u8fd9\u91cc\u662f\u76f4\u63a5\u8f6c\u53d1\u7ed9\u540e\u7aef\u5e94\u7528\u670d\u52a1\u5668\u4e86\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u9759\u6001\u9996\u9875<br \/>\n# \u7b2c\u4e00\u4e2a\u5fc5\u9009\u89c4\u5219<br \/>\nlocation = \/ {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;proxy_pass&nbsp;<a href=\"http:\/\/tomcat:8080\/index\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/tomcat:8080\/index<\/a><br \/>\n}<br \/>\n# \u7b2c\u4e8c\u4e2a\u5fc5\u9009\u89c4\u5219\u662f\u5904\u7406\u9759\u6001\u6587\u4ef6\u8bf7\u6c42\uff0c\u8fd9\u662fnginx\u4f5c\u4e3ahttp\u670d\u52a1\u5668\u7684\u5f3a\u9879<br \/>\n# \u6709\u4e24\u79cd\u914d\u7f6e\u6a21\u5f0f\uff0c\u76ee\u5f55\u5339\u914d\u6216\u540e\u7f00\u5339\u914d,\u4efb\u9009\u5176\u4e00\u6216\u642d\u914d\u4f7f\u7528<br \/>\nlocation ^~ \/static\/ {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;root \/webroot\/static\/;<br \/>\n}<br \/>\nlocation ~* \\.(gif|jpg|jpeg|png|css|js|ico)$ {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;root \/webroot\/res\/;<br \/>\n}<br \/>\n#\u7b2c\u4e09\u4e2a\u89c4\u5219\u5c31\u662f\u901a\u7528\u89c4\u5219\uff0c\u7528\u6765\u8f6c\u53d1\u52a8\u6001\u8bf7\u6c42\u5230\u540e\u7aef\u5e94\u7528\u670d\u52a1\u5668<br \/>\n#\u975e\u9759\u6001\u6587\u4ef6\u8bf7\u6c42\u5c31\u9ed8\u8ba4\u662f\u52a8\u6001\u8bf7\u6c42\uff0c\u81ea\u5df1\u6839\u636e\u5b9e\u9645\u628a\u63e1<br \/>\n#\u6bd5\u7adf\u76ee\u524d\u7684\u4e00\u4e9b\u6846\u67b6\u7684\u6d41\u884c\uff0c\u5e26.<a class=\"replace_word\" title=\"PHP\u77e5\u8bc6\u5e93\" href=\"http:\/\/lib.csdn.net\/base\/php\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">php<\/a>,.jsp\u540e\u7f00\u7684\u60c5\u51b5\u5f88\u5c11\u4e86<br \/>\nlocation \/ {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;proxy_pass&nbsp;<a href=\"http:\/\/tomcat:8080\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/tomcat:8080\/<\/a><br \/>\n}<\/p>\n<p>\u4e09\u3001ReWrite\u8bed\u6cd5<br \/>\nlast \u2013 \u57fa\u672c\u4e0a\u90fd\u7528\u8fd9\u4e2aFlag\u3002<br \/>\nbreak \u2013 \u4e2d\u6b62Rewirte\uff0c\u4e0d\u5728\u7ee7\u7eed\u5339\u914d<br \/>\nredirect \u2013 \u8fd4\u56de\u4e34\u65f6\u91cd\u5b9a\u5411\u7684HTTP\u72b6\u6001302<br \/>\npermanent \u2013 \u8fd4\u56de\u6c38\u4e45\u91cd\u5b9a\u5411\u7684HTTP\u72b6\u6001301<br \/>\n1\u3001\u4e0b\u9762\u662f\u53ef\u4ee5\u7528\u6765\u5224\u65ad\u7684\u8868\u8fbe\u5f0f\uff1a<br \/>\n-f\u548c!-f\u7528\u6765\u5224\u65ad\u662f\u5426\u5b58\u5728\u6587\u4ef6<br \/>\n-d\u548c!-d\u7528\u6765\u5224\u65ad\u662f\u5426\u5b58\u5728\u76ee\u5f55<br \/>\n-e\u548c!-e\u7528\u6765\u5224\u65ad\u662f\u5426\u5b58\u5728\u6587\u4ef6\u6216\u76ee\u5f55<br \/>\n-x\u548c!-x\u7528\u6765\u5224\u65ad\u6587\u4ef6\u662f\u5426\u53ef\u6267\u884c<br \/>\n2\u3001\u4e0b\u9762\u662f\u53ef\u4ee5\u7528\u4f5c\u5224\u65ad\u7684\u5168\u5c40\u53d8\u91cf<br \/>\n\u4f8b\uff1a<a href=\"http:\/\/localhost:88\/test1\/test2\/test.php\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/localhost:88\/test1\/test2\/test.php<\/a><br \/>\n$host\uff1alocalhost<br \/>\n$server_port\uff1a88<br \/>\n$request_uri\uff1a<a href=\"http:\/\/localhost:88\/test1\/test2\/test.php\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/localhost:88\/test1\/test2\/test.php<\/a><br \/>\n$document_uri\uff1a\/test1\/test2\/test.php<br \/>\n$document_root\uff1aD:\\nginx\/html<br \/>\n$request_filename\uff1aD:\\nginx\/html\/test1\/test2\/test.php<br \/>\n\u56db\u3001Redirect\u8bed\u6cd5<br \/>\nserver {<br \/>\nlisten 80;<br \/>\nserver_name start.igrow.cn;<br \/>\nindex index.html index.php;<br \/>\nroot html;<br \/>\nif ($http_host !~ \u201c^star\\.igrow\\.cn$&amp;quot {<br \/>\nrewrite ^(.*)&nbsp;<a href=\"https:\/\/blog.csdn.net\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/star.igrow.cn$1<\/a>&nbsp;redirect;<br \/>\n}<br \/>\n}<br \/>\n\u4e94\u3001\u9632\u76d7\u94fe<br \/>\nlocation ~* \\.(gif|jpg|swf)$ {<br \/>\nvalid_referers none blocked start.igrow.cn sta.igrow.cn;<br \/>\nif ($invalid_referer) {<br \/>\nrewrite ^\/&nbsp;<a href=\"https:\/\/blog.csdn.net\/logo.png\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/$host\/logo.png<\/a>;<br \/>\n}<br \/>\n}<br \/>\n\u516d\u3001\u6839\u636e\u6587\u4ef6\u7c7b\u578b\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4<br \/>\nlocation ~* \\.(js|css|jpg|jpeg|gif|png|swf)$ {<br \/>\nif (-f $request_filename) {<br \/>\nexpires 1h;<br \/>\nbreak;<br \/>\n}<br \/>\n}<br \/>\n\u4e03\u3001\u7981\u6b62\u8bbf\u95ee\u67d0\u4e2a\u76ee\u5f55<br \/>\nlocation ~* \\.(txt|doc)${<br \/>\nroot \/data\/www\/wwwroot\/linuxtone\/test;<br \/>\ndeny all;<br \/>\n}<br \/>\n\u4e00\u4e9b\u53ef\u7528\u7684\u5168\u5c40\u53d8\u91cf:<br \/>\n$args<br \/>\n$content_length<br \/>\n$content_type<br \/>\n$document_root<br \/>\n$document_uri<br \/>\n$host<br \/>\n$http_user_agent<br \/>\n$http_cookie<br \/>\n$limit_rate<br \/>\n$request_body_file<br \/>\n$request_method<br \/>\n$remote_addr<br \/>\n$remote_port<br \/>\n$remote_user<br \/>\n$request_filename<br \/>\n$request_uri<br \/>\n$query_string<br \/>\n$scheme<br \/>\n$server_protocol<br \/>\n$server_addr<br \/>\n$server_name<br \/>\n$server_port<br \/>\n$uri<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u81ea https:\/\/blog.csdn.net\/abel004\/article &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/www.sulabs.net\/?p=880\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[119],"class_list":["post-880","post","type-post","status-publish","format-standard","hentry","category-lamp","tag-nginx"],"_links":{"self":[{"href":"https:\/\/www.sulabs.net\/index.php?rest_route=\/wp\/v2\/posts\/880","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sulabs.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sulabs.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sulabs.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sulabs.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=880"}],"version-history":[{"count":3,"href":"https:\/\/www.sulabs.net\/index.php?rest_route=\/wp\/v2\/posts\/880\/revisions"}],"predecessor-version":[{"id":958,"href":"https:\/\/www.sulabs.net\/index.php?rest_route=\/wp\/v2\/posts\/880\/revisions\/958"}],"wp:attachment":[{"href":"https:\/\/www.sulabs.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sulabs.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=880"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sulabs.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}