{"id":177813,"date":"2020-05-03T09:07:07","date_gmt":"2020-05-03T01:07:07","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=177813"},"modified":"2020-04-22T16:08:28","modified_gmt":"2020-04-22T08:08:28","slug":"nginx-configuration-web","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/nginx-configuration-web.html","title":{"rendered":"\u8be6\u89e3Nginx\u5982\u4f55\u914d\u7f6eWeb\u670d\u52a1\u5668"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86\u8be6\u89e3 Nginx\u5982\u4f55\u914d\u7f6eWeb\u670d\u52a1\u5668\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u6587\u4e2d\u901a\u8fc7\u793a\u4f8b\u4ee3\u7801\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6\uff0c\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6216\u8005\u5de5\u4f5c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u5b66\u4e60\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u4eec\u4e0b\u9762\u968f\u7740\u5c0f\u7f16\u6765\u4e00\u8d77\u5b66\u4e60\u5b66\u4e60\u5427<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u6982\u8ff0<\/strong><\/div>\n

\u4eca\u5929\u4e3b\u8981\u5206\u4eab\u600e\u4e48\u5c06NGINX\u914d\u7f6e\u4f5c\u4e3aWeb\u670d\u52a1\u5668\uff0c\u5e76\u5305\u62ec\u4ee5\u4e0b\u90e8\u5206\uff1a
\n\u2022\u8bbe\u7f6e\u865a\u62df\u670d\u52a1\u5668
\n\u2022\u914d\u7f6e\u4f4d\u7f6e
\n\u2022\u4f7f\u7528\u53d8\u91cf
\n\u2022\u8fd4\u56de\u7279\u5b9a\u72b6\u6001\u7801
\n\u2022\u91cd\u5199HTTP\u54cd\u5e94
\n\u5728\u9ad8\u5c42\u6b21\u4e0a\uff0c\u5c06NGINX\u914d\u7f6e\u4f5c\u4e3aWeb\u670d\u52a1\u5668\u6709\u4e00\u4e9b\u95ee\u9898\u9700\u8981\u4e86\u89e3\uff0c\u5b9a\u4e49\u5b83\u5904\u7406\u54ea\u4e9bURL\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u8fd9\u4e9bURL\u4e0a\u7684\u8d44\u6e90\u7684HTTP\u8bf7\u6c42\u3002 \u5728\u8f83\u4f4e\u5c42\u6b21\u4e0a\uff0c\u914d\u7f6e\u5b9a\u4e49\u4e86\u4e00\u7ec4\u63a7\u5236\u5bf9\u7279\u5b9a\u57df\u6216IP\u5730\u5740\u7684\u8bf7\u6c42\u7684\u5904\u7406\u7684\u865a\u62df\u670d\u52a1\u5668\u3002
\n\u7528\u4e8eHTTP\u6d41\u91cf\u7684\u6bcf\u4e2a\u865a\u62df\u670d\u52a1\u5668\u5b9a\u4e49\u4e86\u79f0\u4e3a\u4f4d\u7f6e\u7684\u7279\u6b8a\u914d\u7f6e\u5b9e\u4f8b\uff0c\u5b83\u4eec\u63a7\u5236\u7279\u5b9aURI\u96c6\u5408\u7684\u5904\u7406\u3002 \u6bcf\u4e2a\u4f4d\u7f6e\u5b9a\u4e49\u4e86\u81ea\u5df1\u7684\u6620\u5c04\u5230\u6b64\u4f4d\u7f6e\u7684\u8bf7\u6c42\u53d1\u751f\u7684\u60c5\u51b5\u3002 NGINX\u53ef\u4ee5\u5b8c\u5168\u63a7\u5236\u8fd9\u4e2a\u8fc7\u7a0b\u3002 \u6bcf\u4e2a\u4f4d\u7f6e\u90fd\u53ef\u4ee5\u4ee3\u7406\u8bf7\u6c42\u6216\u8fd4\u56de\u4e00\u4e2a\u6587\u4ef6\u3002 \u6b64\u5916\uff0c\u53ef\u4ee5\u4fee\u6539URI\uff0c\u4ee5\u4fbf\u5c06\u8bf7\u6c42\u91cd\u5b9a\u5411\u5230\u53e6\u4e00\u4e2a\u4f4d\u7f6e\u6216\u865a\u62df\u670d\u52a1\u5668\u3002 \u6b64\u5916\uff0c\u53ef\u4ee5\u8fd4\u56de\u7279\u5b9a\u7684\u9519\u8bef\u4ee3\u7801\uff0c\u4e5f\u53ef\u4ee5\u914d\u7f6e\u7279\u5b9a\u7684\u9875\u9762\u4ee5\u5bf9\u5e94\u4e8e\u6bcf\u4e2a\u9519\u8bef\u4ee3\u7801\u3002
\n\"\"<\/p>\n

1. \u8bbe\u7f6e\u865a\u62df\u670d\u52a1\u5668<\/strong><\/div>\n

NGINX\u914d\u7f6e\u6587\u4ef6\u5fc5\u987b\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u670d\u52a1\u5668\u6307\u4ee4\u6765\u5b9a\u4e49\u865a\u62df\u670d\u52a1\u5668\u3002 \u5f53NGINX\u5904\u7406\u8bf7\u6c42\u65f6\uff0c\u5b83\u9996\u5148\u9009\u62e9\u63d0\u4f9b\u8bf7\u6c42\u7684\u865a\u62df\u670d\u52a1\u5668\u3002
\n\u865a\u62df\u670d\u52a1\u5668\u7531http\u4e0a\u4e0b\u6587\u4e2d\u7684\u670d\u52a1\u5668\u6307\u4ee4\u5b9a\u4e49\uff0c\u4f8b\u5982\uff1a<\/p>\n

\r\nhttp { \r\n server { \r\n # Server configuration \r\n } \r\n}\r\n<\/pre>\n

\u53ef\u4ee5\u5c06\u591a\u4e2aserver\u6307\u4ee4\u6dfb\u52a0\u5230http\u4e0a\u4e0b\u6587\u4e2d\u4ee5\u5b9a\u4e49\u591a\u4e2a\u865a\u62df\u670d\u52a1\u5668\u3002
\nserver\u914d\u7f6e\u5757\u901a\u5e38\u5305\u62ec\u4e00\u4e2alisten\u6307\u4ee4\uff0c\u7528\u4e8e\u6307\u5b9a\u670d\u52a1\u5668\u4fa6\u542c\u8bf7\u6c42\u7684IP\u5730\u5740\u548c\u7aef\u53e3(\u6216Unix\u57df\u5957\u63a5\u5b57\u548c\u8def\u5f84)\u3002IPv4\u548cIPv6\u5730\u5740\u5747\u88ab\u63a5\u53d7; \u5c06\u65b9\u62ec\u53f7(\u3002
\n\u4e0b\u9762\u7684\u793a\u4f8b\u663e\u793a\u4e86\u76d1\u542cIP\u5730\u5740127.0.0.1\u548c\u7aef\u53e38080\u7684\u670d\u52a1\u5668\u7684\u914d\u7f6e\uff1a<\/p>\n

\r\nserver { \r\n listen 127.0.0.1:8080; \r\n # The rest of server configuration \r\n}\r\n<\/pre>\n

\u5982\u679c\u7701\u7565\u7aef\u53e3\uff0c\u5219\u4f7f\u7528\u6807\u51c6\u7aef\u53e3\u3002 \u540c\u6837\u5730\uff0c\u5982\u679c\u7701\u7565\u4e00\u4e2a\u5730\u5740\uff0c\u670d\u52a1\u5668\u5c06\u4fa6\u542c\u6240\u6709\u5730\u5740\u3002 \u5982\u679c\u6ca1\u6709\u5305\u542blisten\u6307\u4ee4\uff0c\u5219\u201c\u6807\u51c6\u201d\u7aef\u53e3\u4e3a80\/tcp\uff0c\u201cdefault\u201d\u7aef\u53e3\u4e3a8000\/tcp\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u8d85\u7ea7\u7528\u6237\u6743\u9650\u3002
\n\u5982\u679c\u6709\u591a\u4e2a\u670d\u52a1\u5668\u4e0e\u8bf7\u6c42\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u76f8\u5339\u914d\uff0c\u5219NGINX\u5c06\u6839\u636e\u670d\u52a1\u5668\u5757\u4e2d\u7684server_name\u6307\u4ee4\u6d4b\u8bd5\u8bf7\u6c42\u7684\u4e3b\u673a\u5934\u57df\u3002 server_name\u7684\u53c2\u6570\u53ef\u4ee5\u662f\u5b8c\u6574(\u7cbe\u786e)\u540d\u79f0\uff0c\u901a\u914d\u7b26\u6216\u6b63\u5219\u8868\u8fbe\u5f0f\u3002 \u901a\u914d\u7b26\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5176\u5f00\u5934\uff0c\u7ed3\u5c3e\u6216\u4e24\u8005\u90fd\u5305\u542b\u661f\u53f7(*); \u661f\u53f7\u5339\u914d\u4efb\u4f55\u5b57\u7b26\u5e8f\u5217\u3002 NGINX\u5c06Perl\u8bed\u6cd5\u7528\u4e8e\u6b63\u5219\u8868\u8fbe\u5f0f; \u5728\u5b83\u4eec\u4e4b\u524d\u4f7f\u7528\u6ce2\u6d6a\u53f7()\u3002 \u6b64\u793a\u4f8b\u8bf4\u660e\u4e86\u4e00\u4e2a\u786e\u5207\u7684\u540d\u79f0\u3002<\/p>\n

\r\nserver { \r\n listen 80; \r\n server_name example.org www.example.org; \r\n ... \r\n}\r\n<\/pre>\n
2. \u914d\u7f6e\u4f4d\u7f6e<\/strong><\/div>\n

NGINX\u53ef\u4ee5\u6839\u636e\u8bf7\u6c42URI\u5411\u4e0d\u540c\u7684\u4ee3\u7406\u53d1\u9001\u6d41\u91cf\u6216\u63d0\u4f9b\u4e0d\u540c\u7684\u6587\u4ef6\u3002 \u8fd9\u4e9b\u5757\u662f\u4f7f\u7528\u653e\u7f6e\u5728server\u6307\u4ee4\u4e2d\u7684location\u6307\u4ee4\u6765\u5b9a\u4e49\u7684\u3002
\n\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u5b9a\u4e49\u4e09\u4e2alocation\u5757\uff0c\u4ee5\u6307\u793a\u865a\u62df\u670d\u52a1\u5668\u5411\u4e00\u4e2a\u4ee3\u7406\u670d\u52a1\u5668\u53d1\u9001\u4e00\u4e9b\u8bf7\u6c42\uff0c\u5c06\u5176\u4ed6\u8bf7\u6c42\u53d1\u9001\u5230\u4e0d\u540c\u7684\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u5e76\u901a\u8fc7\u4ece\u672c\u5730\u6587\u4ef6\u7cfb\u7edf\u4f20\u9012\u6587\u4ef6\u6765\u63d0\u4f9b\u5176\u4f59\u8bf7\u6c42\u3002
\nNGINX\u6d4b\u8bd5\u6839\u636e\u6240\u6709location\u6307\u4ee4\u7684\u53c2\u6570\u8bf7\u6c42URI\uff0c\u5e76\u5e94\u7528\u5339\u914dlocation\u4e2d\u5b9a\u4e49\u7684\u6307\u4ee4\u3002 \u5728\u6bcf\u4e2alocation\u5757\u5185\uff0c\u901a\u5e38\u53ef\u80fd(\u9664\u4e86\u4e00\u4e9b\u4f8b\u5916)\u653e\u7f6e\u66f4\u591a\u7684location\u6307\u4ee4\u4ee5\u8fdb\u4e00\u6b65\u7ec6\u5316\u7279\u5b9a\u7ec4\u8bf7\u6c42\u7684\u5904\u7406\u3002
\n\u6ce8\u610f\uff1a\u5728\u672c\u6559\u7a0b\u6587\u7ae0\u4e2d\uff0c\u5355\u8bcdlocation\u662f\u6307\u5355\u4e2alocation\u4e0a\u4e0b\u6587\u3002
\nlocation\u6307\u4ee4\u6709\u4e24\u79cd\u7c7b\u578b\u7684\u53c2\u6570\uff1a\u524d\u7f00\u5b57\u7b26\u4e32(\u8def\u5f84\u540d)\u548c\u6b63\u5219\u8868\u8fbe\u5f0f\u3002 \u5bf9\u4e8e\u8981\u5339\u914d\u524d\u7f00\u5b57\u7b26\u4e32\u7684\u8bf7\u6c42URI\uff0c\u5fc5\u987b\u4ee5\u524d\u7f00\u5b57\u7b26\u4e32\u5f00\u5934\u3002
\n\u5177\u6709pathname\u53c2\u6570\u7684\u4ee5\u4e0b\u793a\u4f8b\u4f4d\u7f6e\u5339\u914d\u4ee5\/some\/path\/\u5f00\u5934\u7684\u8bf7\u6c42URI\uff0c\u4f8b\u5982\/some\/path\/document.html\uff0c\u5b83\u4e0d\u5339\u914d\/my-site\/some\/path\uff0c\u56e0\u4e3a\/some\/path\u4e0d\u5728\u8be5URI\u7684\u5f00\u5934\u51fa\u73b0\u3002<\/p>\n

\r\nlocation \/some\/path\/ { \r\n ... \r\n}\r\n<\/pre>\n

\u6b63\u5219\u8868\u8fbe\u5f0f\u4e4b\u524d\u662f\u533a\u5206\u5927\u5c0f\u5199\u5339\u914d\u7684\u6ce2\u5f62\u7b26\u53f7(~)\uff0c\u6216\u8005\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u5339\u914d\u7684\u6ce2\u5f62\u7b26\u53f7(~*)\u3002 \u4ee5\u4e0b\u793a\u4f8b\u5c06\u5305\u542b\u5b57\u7b26\u4e32.html\u6216.html\u7684URI\u4e0e\u4efb\u4f55\u4f4d\u7f6e\u76f8\u5339\u914d\u3002<\/p>\n

\r\nlocation ~ \\.html? { \r\n ... \r\n}\r\n<\/pre>\n

\u8981\u627e\u5230\u6700\u7b26\u5408URI\u7684\u4f4d\u7f6e\uff0cNGINX\u9996\u5148\u5c06URI\u4e0e\u524d\u7f00\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\u8fdb\u884c\u6bd4\u8f83\u3002\u7136\u540e\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u641c\u7d22\u4f4d\u7f6e\u3002
\nlocation\u4e0a\u4e0b\u6587\u53ef\u4ee5\u5305\u542b\u5b9a\u4e49\u5982\u4f55\u89e3\u6790\u8bf7\u6c42\u7684\u6307\u4ee4 - \u63d0\u4f9b\u9759\u6001\u6587\u4ef6\u6216\u5c06\u8bf7\u6c42\u4f20\u9012\u7ed9\u4ee3\u7406\u7684\u670d\u52a1\u5668\u3002 \u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d\uff0c\u5339\u914d\u7b2c\u4e00\u4e2alocation\u4e0a\u4e0b\u6587\u7684\u8bf7\u6c42\u5c06\u4ece\/data\/images\u76ee\u5f55\u4e2d\u63d0\u4f9b\u6587\u4ef6\uff0c\u5e76\u5c06\u5339\u914d\u7b2c\u4e8c\u4e2a\u4f4d\u7f6e\u7684\u8bf7\u6c42\u4f20\u9012\u7ed9\u627f\u8f7d www.example.com \u57df\u5185\u5bb9\u7684\u4ee3\u7406\u670d\u52a1\u5668\u3002<\/p>\n

\r\nserver { \r\n location \/images\/ { \r\n root \/data; \r\n } \r\n location \/ { \r\n proxy_pass http:\/\/www.example.com; \r\n } \r\n}\r\n<\/pre>\n

root\u6307\u4ee4\u6307\u5b9a\u8981\u5728\u5176\u4e2d\u641c\u7d22\u8981\u63d0\u4f9b\u7684\u9759\u6001\u6587\u4ef6\u7684\u6587\u4ef6\u7cfb\u7edf\u8def\u5f84\u3002 \u4e0e\u8be5\u4f4d\u7f6e\u76f8\u5173\u8054\u7684\u8bf7\u6c42URI\u5c06\u9644\u52a0\u5230\u8def\u5f84\uff0c\u4ee5\u83b7\u53d6\u8981\u63d0\u4f9b\u7684\u9759\u6001\u6587\u4ef6\u7684\u5168\u540d\u3002 \u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u8981\u54cd\u5e94\/images\/logo.png\u7684\u8bf7\u6c42\uff0cNGINX\u63d0\u4f9b\u670d\u52a1\u5668\u672c\u5730\u5b9e\u9645\u5bf9\u5e94\u6587\u4ef6\u662f\uff1a\/data\/images\/logo.png\u3002
\nproxy_pass\u6307\u4ee4\u5c06\u8bf7\u6c42\u4f20\u9012\u7ed9\u4f7f\u7528\u914d\u7f6e\u7684URL\u8bbf\u95ee\u4ee3\u7406\u670d\u52a1\u5668\u3002\u7136\u540e\u5c06\u4ee3\u7406\u670d\u52a1\u5668\u7684\u54cd\u5e94\u4f20\u56de\u5ba2\u6237\u7aef\u3002\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6240\u6709\u4e0d\u4ee5\/images\/\u5f00\u5934\u7684URI\u7684\u8bf7\u6c42\u90fd\u5c06\u88ab\u4f20\u9012\u7ed9\u4ee3\u7406\u7684\u670d\u52a1\u5668(\u4e5f\u5c31\u662f\uff1awww.example.com)\u3002<\/p>\n

3. \u4f7f\u7528\u53d8\u91cf<\/strong><\/div>\n

\u53ef\u4ee5\u4f7f\u7528\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u53d8\u91cf\uff0c\u4f7fNGINX\u8fdb\u7a0b\u7684\u8bf7\u6c42\u6839\u636e\u5b9a\u4e49\u7684\u60c5\u51b5\u800c\u6709\u6240\u4e0d\u540c\u3002 \u53d8\u91cf\u662f\u5728\u8fd0\u884c\u65f6\u8ba1\u7b97\u7684\u547d\u540d\u503c\uff0c\u7528\u4f5c\u6307\u4ee4\u7684\u53c2\u6570\u3002 \u4e00\u4e2a\u53d8\u91cf\u7531\u5b83\u7684\u540d\u5b57\u5f00\u5934\u7684$(\u7f8e\u5143)\u7b26\u53f7\u8868\u793a\u3002 \u53d8\u91cf\u6839\u636eNGINX\u7684\u72b6\u6001\u5b9a\u4e49\u4fe1\u606f\uff0c\u4f8b\u5982\u6b63\u5728\u5904\u7406\u7684\u8bf7\u6c42\u7684\u5c5e\u6027\u3002
\n\u6709\u8bb8\u591a\u9884\u5b9a\u4e49\u7684\u53d8\u91cf\uff0c\u5982\u6838\u5fc3HTTP\u53d8\u91cf\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528set\uff0cmap\u548cgeo\u6307\u4ee4\u5b9a\u4e49\u81ea\u5b9a\u4e49\u53d8\u91cf\u3002 \u5927\u591a\u6570\u53d8\u91cf\u5728\u8fd0\u884c\u65f6\u8ba1\u7b97\u7684\uff0c\u5e76\u5305\u542b\u4e0e\u7279\u5b9a\u8bf7\u6c42\u76f8\u5173\u7684\u4fe1\u606f\u3002 \u4f8b\u5982\uff0c$remote_addr\u5305\u542b\u5ba2\u6237\u7aefIP\u5730\u5740\uff0c$uri\u4fdd\u5b58\u5f53\u524d\u7684URI\u503c\u3002<\/p>\n

4. \u8fd4\u56de\u7279\u5b9a\u72b6\u6001\u7801<\/strong><\/div>\n

\u4e00\u4e9b\u7f51\u7ad9URI\u9700\u8981\u7acb\u5373\u8fd4\u56de\u5177\u6709\u7279\u5b9a\u9519\u8bef\u6216\u91cd\u5b9a\u5411\u4ee3\u7801\u7684\u54cd\u5e94\uff0c\u4f8b\u5982\u5f53\u9875\u9762\u88ab\u6682\u65f6\u79fb\u52a8\u6216\u6c38\u4e45\u79fb\u52a8\u65f6\u3002 \u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528return\u6307\u4ee4\u3002 \u4f8b\u5982\u8fd4\u56de\u672a\u627e\u5230\u7684404\u72b6\u6001\u7801\uff1a<\/p>\n

\r\nlocation \/wrong\/url { \r\n return 404; \r\n}\r\n<\/pre>\n

\u8fd4\u56de\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u54cd\u5e94\u4ee3\u7801\u3002\u53ef\u9009\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u53ef\u4ee5\u662f\u91cd\u5b9a\u5411\u7684URL(\u4ee3\u7801301,302,303\u548c307)\u6216\u5728\u54cd\u5e94\u4f53\u4e2d\u8fd4\u56de\u6587\u672c\u3002 \u4f8b\u5982\uff1a<\/p>\n

\r\nlocation \/permanently\/moved\/url { \r\n return 301 http:\/\/www.example.com\/moved\/here; \r\n}\r\n<\/pre>\n

\u8fd4\u56de\u6307\u4ee4\u53ef\u4ee5\u5305\u542b\u5728 location \u548c server \u4e0a\u4e0b\u6587\u4e2d\u3002<\/p>\n

5. \u91cd\u5199HTTP\u54cd\u5e94<\/strong><\/div>\n

\u6709\u65f6\u9700\u8981\u91cd\u5199\u6216\u66f4\u6539HTTP\u54cd\u5e94\u4e2d\u7684\u5185\u5bb9\uff0c\u5c06\u4e00\u4e2a\u5b57\u7b26\u4e32\u66ff\u6362\u4e3a\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002 \u53ef\u4ee5\u4f7f\u7528sub_filter\u6307\u4ee4\u6765\u5b9a\u4e49\u8981\u5e94\u7528\u7684\u91cd\u5199\u3002 \u8be5\u6307\u4ee4\u652f\u6301\u53d8\u91cf\u548c\u66ff\u4ee3\u94fe\uff0c\u4f7f\u66f4\u590d\u6742\u7684\u66f4\u6539\u6210\u4e3a\u53ef\u80fd\u3002
\n\u4f8b\u5982\uff0c\u53ef\u4ee5\u66f4\u6539\u5f15\u7528\u9664\u4ee3\u7406\u670d\u52a1\u5668\u4e4b\u5916\u7684\u7edd\u5bf9\u94fe\u63a5\uff1a<\/p>\n

\r\nlocation \/ { \r\n sub_filter \/blog\/ \/blog-staging\/; \r\n sub_filter_once off; \r\n}\r\n<\/pre>\n

\u53e6\u4e00\u4e2a\u793a\u4f8b\u5c06\u65b9\u6cd5\u4ecehttp:\/\/\u66f4\u6539\u4e3ahttp:\/\/\uff0c\u5e76\u4ece\u8bf7\u6c42\u5934\u57df\u66ff\u6362\u672c\u5730\u4e3b\u673a\u5730\u5740\u5230\u4e3b\u673a\u540d\u3002 sub_filter_once\u6307\u4ee4\u544a\u8bc9NGINX\u5728\u4e00\u4e2a\u4f4d\u7f6e(location)\u5185\u8fde\u7eed\u5e94\u7528sub_filter\u4f2a\u6307\u4ee4\uff1a<\/p>\n

\r\nlocation \/ { \r\n sub_filter 'href=\"http:\/\/127.0.0.1:8080\/' 'href=\"http:\/\/$host\/'; \r\n sub_filter 'img src=\"http:\/\/127.0.0.1:8080\/' 'img src=\"http:\/\/$host\/'; \r\n sub_filter_once on; \r\n}\r\n<\/pre>\n

\u8bf7\u6ce8\u610f\uff0c\u5982\u679c\u53d1\u751f\u53e6\u4e00\u4e2asub_filter\u5339\u914d\uff0c\u5219\u4f7f\u7528sub_filter\u4fee\u6539\u7684\u54cd\u5e94\u90e8\u5206\u5c06\u4e0d\u518d\u88ab\u66ff\u6362\u3002
\n\u5230\u6b64\u8fd9\u7bc7\u5173\u4e8e\u8be6\u89e3Nginx\u5982\u4f55\u914d\u7f6eWeb\u670d\u52a1\u5668\u7684\u793a\u4f8b\u4ee3\u7801\u7684\u6587\u7ae0\u5c31\u4ecb\u7ecd\u5230\u8fd9\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4eca\u5929\u4e3b\u8981\u5206\u4eab\u600e\u4e48\u5c06NGINX\u914d\u7f6e\u4f5c\u4e3aWeb\u670d\u52a1\u5668\uff0c\u5e76\u5305\u62ec\u4ee5\u4e0b\u90e8\u5206\uff1a \u2022\u8bbe\u7f6e\u865a\u62df\u670d\u52a1\u5668 \u2022\u914d\u7f6e\u4f4d\u7f6e \u2022\u4f7f\u7528\u53d8\u91cf […]<\/p>\n","protected":false},"author":1893,"featured_media":177810,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-177813","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/177813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1893"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=177813"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/177813\/revisions"}],"predecessor-version":[{"id":177820,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/177813\/revisions\/177820"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/177810"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=177813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=177813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=177813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}