{"id":457,"date":"2023-02-25T13:24:21","date_gmt":"2023-02-25T05:24:21","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=457"},"modified":"2023-04-29T20:59:35","modified_gmt":"2023-04-29T12:59:35","slug":"path-mapping-issue-after-nginx-location-configuration-path-replacement","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/path-mapping-issue-after-nginx-location-configuration-path-replacement\/","title":{"rendered":"Nginx location \u914d\u7f6e\u540e\u8def\u5f84\u6620\u5c04\u95ee\u9898\uff08\u8def\u5f84\u66ff\u6362\uff09"},"content":{"rendered":"<h2>location proxy_pass<\/h2>\n<p>Nginx\u914d\u7f6e<code>location proxy_pass<\/code>\u65f6\u53ef\u4ee5\u5b9e\u73b0URL\u8def\u5f84\u7684\u90e8\u5206\u66ff\u6362\u3002<\/p>\n<blockquote>\n<p>\uff081\uff09<code>proxy_pass<\/code>\u7684\u76ee\u6807\u5730\u5740\uff0c\u9ed8\u8ba4\u4e0d\u5e26<code>\/<\/code>\uff0c\u8868\u793a\u53ea\u4ee3\u7406\u57df\u540d\uff0c<code>url<\/code>\u548c<code>querystring<\/code>\u90e8\u5206\u4e0d\u4f1a\u53d8\uff08\u628a\u8bf7\u6c42\u7684<code>path<\/code>\u62fc\u63a5\u5230<code>proxy_pass<\/code>\u76ee\u6807\u57df\u540d\u4e4b\u540e\u4f5c\u4e3a\u4ee3\u7406\u7684URL\uff09<\/p>\n<p>\uff082\uff09\u5982\u679c\u5728\u76ee\u6807\u5730\u5740\u540e\u589e\u52a0<code>\/<\/code>\uff0c\u5219\u8868\u793a\u628a<code>path<\/code>\u4e2d<code>location<\/code>\u5339\u914d\u6210\u529f\u7684\u90e8\u5206\u526a\u5207\u6389\u4e4b\u540e\u518d\u62fc\u63a5\u5230<code>proxy_pass<\/code>\u76ee\u6807\u5730\u5740<\/p>\n<\/blockquote>\n<p><!-- more --><\/p>\n<p>\u4f8b\u5b50\uff1a<\/p>\n<pre><code class=\"language-json\">server {\n    location \/abc {\n        proxy_pass http:\/\/server_url;\n    }\n\n    location \/abc {\n        proxy_pass http:\/\/server_url\/;\n    }\n}<\/code><\/pre>\n<p>\u6bd4\u5982\u8bf7\u6c42<code>\/abc\/b.html<\/code><\/p>\n<p>\u5982\u4e0a\u4e24\u4e2a\u5339\u914d\u6210\u529f\u540e\uff0c\u5b9e\u9645\u4ee3\u7406\u7684\u76ee\u6807url\u5206\u522b\u662f<\/p>\n<ul>\n<li><code>http:\/\/server_url\/abc\/b.html<\/code> (\u628a<code>\/abc\/b.html<\/code>\u62fc\u63a5\u5230<code>http:\/\/server_url<\/code>\u4e4b\u540e)<\/li>\n<li><code>http:\/\/server_url\/b.html<\/code> (\u628a<code>\/abc\/b.html<\/code>\u7684<code>\/abc<\/code>\u53bb\u6389\u4e4b\u540e\uff0c\u62fc\u63a5\u5230<code>http:\/\/server_url\/<\/code>\u4e4b\u540e)<\/li>\n<\/ul>\n<h2>proxy_pass \u6d4b\u8bd5<\/h2>\n<pre><code class=\"language-bash\">#--------proxy_pass\u914d\u7f6e---------------------\nlocation \/t1\/ { proxy_pass http:\/\/servers; }    #\u6b63\u5e38\uff0c\u4e0d\u622a\u65ad\nlocation \/t2\/ { proxy_pass http:\/\/servers\/; }    #\u6b63\u5e38\uff0c\u622a\u65ad\nlocation \/t3  { proxy_pass http:\/\/servers; }    #\u6b63\u5e38\uff0c\u4e0d\u622a\u65ad\nlocation \/t4  { proxy_pass http:\/\/servers\/; }    #\u6b63\u5e38\uff0c\u622a\u65ad\nlocation \/t5\/ { proxy_pass http:\/\/servers\/test\/; }    #\u6b63\u5e38\uff0c\u622a\u65ad\nlocation \/t6\/ { proxy_pass http:\/\/servers\/test; }    #\u7f3a&quot;\/&quot;\uff0c\u622a\u65ad\nlocation \/t7  { proxy_pass http:\/\/servers\/test\/; }    #\u542b&quot;\/\/&quot;\uff0c\u622a\u65ad\nlocation \/t8  { proxy_pass http:\/\/servers\/test; }    #\u6b63\u5e38\uff0c\u622a\u65ad<\/code><\/pre>\n<p>\u6d4b\u8bd5\u811a\u672c<\/p>\n<pre><code class=\"language-bash\">for i in $(seq 8)\ndo\n    url=http:\/\/tapi.xxxx.com\/t$i\/doc\/index.html\n    echo &quot;-----------$url-----------&quot;\n    curl url\ndone<\/code><\/pre>\n<p>\u6d4b\u8bd5\u7ed3\u679c<\/p>\n<pre><code class=\"language-bash\">----------http:\/\/tapi.xxxx.com\/t1\/doc\/index.html------------\n\/t1\/doc\/index.html\n\n----------http:\/\/tapi.xxxx.com\/t2\/doc\/index.html------------\n\/doc\/index.html\n\n----------http:\/\/tapi.xxxx.com\/t3\/doc\/index.html------------\n\/t3\/doc\/index.html\n\n----------http:\/\/tapi.xxxx.com\/t4\/doc\/index.html------------\n\/doc\/index.html\n\n----------http:\/\/tapi.xxxx.com\/t5\/doc\/index.html------------\n\/test\/doc\/index.html\n\n----------http:\/\/tapi.xxxx.com\/t6\/doc\/index.html------------\n\/testdoc\/index.html\n\n----------http:\/\/tapi.xxxx.com\/t7\/doc\/index.html------------\n\/test\/\/doc\/index.html\n\n----------http:\/\/tapi.xxxx.com\/t8\/doc\/index.html------------\n\/test\/doc\/index.html<\/code><\/pre>\n<h2>\u6ce8\u610f\u4e8b\u9879<\/h2>\n<p>\u82e5\u622a\u65ad\u66ff\u6362\u540e\u7684URL\u4e2d\u5305\u542b<code>\/\/<\/code>\uff0c\u53ef\u80fd\u4f1a\u62a5\u5982\u4e0b\u9519\u8bef\uff1a<\/p>\n<pre><code class=\"language-bash\">[org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[\/].[dispatcherServlet]] [log] [175] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception\norg.springframework.security.web.firewall.RequestRejectedException: The request was rejected because the URL was not normalized.<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>location proxy_pass Nginx\u914d\u7f6elocation proxy_pass\u65f6\u53ef\u4ee5\u5b9e\u73b0URL\u8def [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[25],"class_list":["post-457","post","type-post","status-publish","format-standard","hentry","category-devops-base","tag-nginx"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=457"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/457\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}