{"id":100,"date":"2023-03-10T14:31:08","date_gmt":"2023-03-10T06:31:08","guid":{"rendered":"https:\/\/my.leaf.hair\/?p=100"},"modified":"2023-03-10T14:38:57","modified_gmt":"2023-03-10T06:38:57","slug":"nginx%e6%9b%bf%e6%8d%a2%e5%93%8d%e5%ba%94%e5%86%85%e5%ae%b9","status":"publish","type":"post","link":"https:\/\/my.di.cloudns.asia\/index.php\/2023\/03\/10\/100.html","title":{"rendered":"Nginx\u66ff\u6362\u54cd\u5e94\u5185\u5bb9"},"content":{"rendered":"<blockquote>\n<p>\u3000\u3000\u56e0\u4e3a\u60f3\u8981\u5c06\u672c\u5730\u524d\u540e\u7aef\u7a0b\u5e8f\u5185\u7f51\u7a7f\u900f\u81f3\u5916\u7f51\uff0c\u5e76\u4e14\u4e92\u4e0d\u5f71\u54cd\u8bbf\u95ee<\/p>\n<\/blockquote>\n<h4>\u4e00\u3001\u7b80\u5355\u66ff\u6362\u6a21\u5757 ngx_http_sub_module\uff1a<\/h4>\n<h5>\uff081\uff09\u4ecb\u7ecd\uff1a<\/h5>\n<blockquote>\n<p>ngx_http_sub_module\u6a21\u5757\u662f\u4e00\u4e2a\u8fc7\u6ee4\u5668\uff0c\u5b83\u4fee\u6539\u7f51\u7ad9\u54cd\u5e94\u5185\u5bb9\u4e2d\u7684\u5b57\u7b26\u4e32\u3002\u8fd9\u4e2a\u6a21\u5757\u5df2\u7ecf\u5185\u7f6e\u5728nginx\u4e2d\uff0c\u4f46\u662f\u9ed8\u8ba4\u672a\u5b89\u88c5\uff0c\u9700\u8981\u5b89\u88c5\u9700\u8981\u52a0\u4e0a\u914d\u7f6e\u53c2\u6570\uff1a&#8211;with-http_sub_module \u5982\u679c\u5df2\u7ecf\u5b89\u88c5nginx,\u53ea\u9700\u8981\u518d\u6dfb\u52a0\u8fd9\u4e2a\u6a21\u5757\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<\/blockquote>\n<h5>\uff082\uff09\u5e38\u7528\u6307\u4ee4\uff1a<\/h5>\n<p>2.1 sub_filter\u6307\u4ee4\uff1a sub_filter string\uff08\u539f\u5b57\u7b26\u4e32\uff09 replacement\uff08\u7528\u4e8e\u66ff\u6362\u7684\u5b57\u7b26\u4e32\uff09;<br \/>\n\u7528\u4e8e\u8bbe\u7f6e\u9700\u8981\u4f7f\u7528\u8bf4\u660e\u5b57\u7b26\u4e32\u66ff\u6362\u8bf4\u660e\u5b57\u7b26\u4e32.string\u662f\u8981\u88ab\u66ff\u6362\u7684\u5b57\u7b26\u4e32\uff0creplacement\u662f \u65b0\u7684\u5b57\u7b26\u4e32\uff0c\u5b83\u91cc\u9762\u53ef\u4ee5\u5e26\u53d8\u91cf\u3002<br \/>\n2.2 sub_filter_last_modified\u6307\u4ee4\uff1a sub_filter_last_modified on | off;<br \/>\n\u7528\u4e8e\u8bbe\u7f6e\u7f51\u9875\u5185\u66ff\u6362\u540e\u662f\u5426\u4fee\u6539 \u53ef\u5728nginx.conf\u7684 http, server, location\u4e09\u4e2a\u4f4d\u7f6e\u914d\u7f6e\u4f7f \u7528\uff0c\u9ed8\u8ba4\u503c\u662foff\uff1b<\/p>\n<p>2.3 sub_filter_once\u6307\u4ee4\uff1asub_filter_once on | off;<br \/>\n\u7528\u4e8e\u8bbe\u7f6e\u5b57\u7b26\u4e32\u66ff\u6362\u6b21\u6570\uff0c\u9ed8\u8ba4\u53ea\u66ff\u6362\u4e00\u6b21\u3002\u5982\u679c\u662fon\uff0c\u9ed8\u8ba4\u53ea\u66ff\u6362\u7b2c\u4e00\u6b21\u5339\u914d\u5230\u7684\u5230\u5b57 \u7b26\uff0c\u5982\u679c\u662foff\uff0c\u90a3\u4e48\u6240\u6709\u5339\u914d\u5230\u7684\u5b57\u7b26\u90fd\u4f1a\u88ab\u66ff\u6362\uff1b<\/p>\n<p>2.4 sub_filter_types\u6307\u4ee4\uff1asub_filter_types <em><br \/>\n\u7528\u4e8e\u6307\u5b9a\u9700\u8981\u88ab\u66ff\u6362\u7684MIME\u7c7b\u578b,\u9ed8\u8ba4\u4e3a\u201ctext\/html\u201d\uff0c\u5982\u679c\u5236\u5b9a\u4e3a<\/em>\uff0c\u90a3\u4e48\u6240\u6709\u7684\uff1b<\/p>\n<h5>\uff083\uff09\u8bf4\u660e\uff1a<\/h5>\n<p>3.1\u4ee5\u4e0a\u6307\u4ee4\u53ef\u5728nginx.conf\u7684http, server, location\u4e09\u4e2a\u4f4d\u7f6e\u914d\u7f6e\u4f7f\u7528\uff1b<br \/>\n3.2\u6b64\u6a21\u5757\u66ff\u6362\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff1b<br \/>\n3.3\u652f\u6301\u4e2d\u6587\u66ff\u6362\uff1b<\/p>\n<h5>\uff084\uff09\u793a\u4f8b\uff1a<\/h5>\n<pre><code>location ^~\/im\/ {\n    proxy_pass http:\/\/p.qiao.baidu.com;\n    add_header Access-Control-Allow-Origin *;\n    sub_filter &#039;http:\/\/p.qiao.baidu.com&#039; &#039;https:\/\/www.demo.com&#039;;##\u5c06\u54cd\u5e94\u5185\u5bb9\u4e2d\u7684\u57df\u540d\u66ff\u6362\u6210\u672c\u7ad9\u57df\u540d\n    sub_filter_once off;####\u6240\u6709\u5339\u914d\u5230\u7684\u90fd\u66ff\u6362\n}<\/code><\/pre>\n<h5>\uff085\uff09\u603b\u7ed3\uff1a<\/h5>\n<p>\u4f7f\u7528ngx_http_sub_module\u6a21\u5757\u597d\u5904\u662fnginx\u5185\u7f6e\u8be5\u6a21\u5757\u4f7f\u7528\u65b9\u4fbf\uff0c\u4e0d\u8db3\u4e4b\u5904\u5728\u4e8e\u8be5\u6a21\u5757\u4e0d\u652f\u6301\u6b63\u5219\u66ff\u6362\uff0c\u7075\u6d3b\u6027\u4e0d\u591f<\/p>\n<h4>\u4e8c\u3001\u652f\u6301\u6b63\u5219\u5339\u914d\u66ff\u6362\u7684\u7b2c\u4e09\u65b9\u6a21\u5757<\/h4>\n<p>ngx_http_substitutions_filter_module\uff1a<\/p>\n<h5>\uff081\uff09\u4e0b\u8f7d\u5730\u5740\uff1a<\/h5>\n<p><a href=\"https:\/\/github.com\/yaoweibin\/ngx_http_substitutions_filter_module\/archive\/master.zip\">https:\/\/github.com\/yaoweibin\/ngx_http_substitutions_filter_module\/archive\/master.zip<\/a><\/p>\n<h5>\uff082\uff09\u89e3\u538b\u7f29<\/h5>\n<p>\u5e73\u6ed1\u5347\u7ea7nginx\uff08\u5347\u7ea7\u65b9\u5f0f\u53ef\u53c2\u8003\u524d\u4e00\u7bc7\u6587\u7ae0\u5e73\u6ed1\u6dfb\u52a0ssl\u6a21\u5757\uff1a<a href=\"http:\/\/www.cnblogs.com\/kenwar\/p\/8295907.html\">http:\/\/www.cnblogs.com\/kenwar\/p\/8295907.html<\/a> \uff08\u6dfb\u52a0\u53c2\u6570&#8211;add-module=\/\u6a21\u5757\u89e3\u538b\u540e\u6587\u4ef6\u8def\u5f84\uff09\uff09<\/p>\n<h5>\uff083\uff09\u4f7f\u7528\u8bf4\u660e\uff1a<\/h5>\n<pre><code>location \/ {\n    subs_filter_types text\/html text\/css text\/xml; \n    subs_filter st(\\d*).example.com $1.example.com ir;\n    subs_filter a.example.com s.example.com;\n    subs_filter http:\/\/$host https:\/\/$host;\n}<\/code><\/pre>\n<p>\u4ecegithub\u7ed9\u51fa\u7684\u4f7f\u7528\u793a\u4f8b\u6765\u770b\uff0c\u8fd9\u4e2a\u6a21\u5757\u6d89\u53ca2\u4e2a\u6307\u4ee4\uff1a<\/p>\n<pre><code>* subs_filter_types\nsubs_filter_types \u8bed\u6cd5\uff1a subs_filter_types mime-type [mime-types]\n\u9ed8\u8ba4\uff1a subs_filter_types text\/html\n\u9002\u7528\uff1a http\uff0c server\uff0c location\nsubs_filter_types \u662f\u7528\u6765\u6307\u5b9a\u66ff\u6362\u6587\u4ef6\u7c7b\u578b\u7684 \u9ed8\u8ba4\u4ec5\u4ec5\u66ff\u6362text\/html\u7c7b\u578b\u7684\u6587\u4ef6\u3002\n\n* subs_filter\nsubs_filter \u8bed\u6cd5\uff1a subs_filter source_str destination_str [gior]\n\u9ed8\u8ba4\uff1a none\n\u9002\u7528\uff1a http\uff0cserver\uff0clocation\nsubs_filter \u662f\u7528\u6765\u66ff\u6362\u6587\u672c\u7684\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\ng\uff08\u9ed8\u8ba4\uff09\uff1a\u66ff\u6362\u5339\u914d\u9879\u3002\ni  \uff1a\u533a\u5206\u5927\u5c0f\u5199\u7684\u5339\u914d\no : \u53ea\u5339\u914d\u53d1\u73b0\u7684\u7b2c\u4e00\u4e2a\u3002\nr  : \u6b63\u5219\u5339\u914d\u3002<\/code><\/pre>\n<h5>\uff084\uff09\u6848\u4f8b\u5206\u4eab\uff1a<\/h5>\n<p>\u66ff\u6362\u54cd\u5e94\u5185\u5bb9\u4e2d\u7684\u67d0\u4e2ajs\uff0c\u56e0\u4e3ajs\u7248\u672c\u4e0d\u56fa\u5b9a\uff0c\u8def\u5f84\u662f\u53d8\u52a8\u7684\uff0c\u6240\u4ee5\u7528\u5230\u6b63\u5219<\/p>\n<pre><code>location ^~\/f\/ {\n         proxy_pass http:\/\/xxx.xxxx.com;\n         add_header Access-Control-Allow-Origin *;\n     subs_filter &#039;https:\/\/cdn.jinshuju.net\/assets\/published_forms\/mobile\/application-(.*?(\\.js){1})&#039; &#039;https:\/\/www.demo.com\/comm\/js\/jinshujujsforsmallproject.js&#039; ir ;\n }<\/code><\/pre>\n<h5>\uff085\uff09\u8bf4\u660e\uff1a<\/h5>\n<p>\u5728\u4f7f\u7528\u6b63\u5219\u6a21\u5f0f\u65f6\uff0c\u4e0d\u80fd\u4f7f\u7528nginx\u5185\u7f6e\u53d8\u91cf\uff0c\u6bd4\u5982\uff1a$host\uff0c\u5426\u5219\u4f1a\u51fa\u73b0\u5982\u4e0b\u62a5\u9519\uff1a<br \/>\nnginx: [emerg] match part cannot contain variable during regex mode in *<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u3000\u56e0\u4e3a\u60f3\u8981\u5c06\u672c\u5730\u524d\u540e\u7aef\u7a0b\u5e8f\u5185\u7f51\u7a7f\u900f\u81f3\u5916\u7f51\uff0c\u5e76\u4e14\u4e92\u4e0d\u5f71\u54cd\u8bbf\u95ee \u4e00\u3001\u7b80\u5355\u66ff\u6362\u6a21\u5757 ngx_http_sub_mo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-100","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/posts\/100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/comments?post=100"}],"version-history":[{"count":4,"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/posts\/100\/revisions"}],"predecessor-version":[{"id":104,"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/posts\/100\/revisions\/104"}],"wp:attachment":[{"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/media?parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/categories?post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/tags?post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}