{"id":54,"date":"2025-06-04T22:38:23","date_gmt":"2025-06-04T14:38:23","guid":{"rendered":"https:\/\/www.alantu.top\/?p=54"},"modified":"2025-06-04T22:44:48","modified_gmt":"2025-06-04T14:44:48","slug":"%e4%b8%aa%e4%ba%ba%e7%94%b5%e8%84%91%e9%83%a8%e7%bd%b2%e5%8d%9a%e5%ae%a2%e7%ab%99%ef%bc%8c%e6%97%a0%e9%9c%80%e5%85%ac%e7%bd%91ip%ef%bc%8c%e6%97%a0%e9%9c%80%e7%ab%af%e5%8f%a3%e6%98%a0%e5%b0%84-2","status":"publish","type":"post","link":"https:\/\/alantu.top\/?p=54","title":{"rendered":"\u4e2a\u4eba\u7535\u8111\u90e8\u7f72\u535a\u5ba2\u7ad9\uff0c\u65e0\u9700\u516c\u7f51IP\uff0c\u65e0\u9700\u7aef\u53e3\u6620\u5c04"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">\u2014\u2014\u2014\u2014\u2013\u7cfb\u5217\u2461<\/h5>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">      Cloudflare Tunnel\u90e8\u7f72WordPress\u65f6\u7684\u4e00\u4e2a\u7ecf\u5178\u6545\u969c\u3002&#8221;\u53d1\u5e03\u5931\u8d25&#8221;\u95ee\u9898\u3002\u6839\u672c\u539f\u56e0\u662f<strong>Cloudflare Tunnel\u4e0eWordPress\u7684REST API\u901a\u4fe1\u51b2\u7a81<\/strong>\uff0c\u6211\u4eec\u5c06\u4ece\u5e95\u5c42\u539f\u7406\u5f00\u59cb\u4fee\u590d\uff1a\u95ee\u9898\u6839\u6e90\u6df1\u5ea6\u5206\u6790<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Tunnel\u7684\u8bf7\u6c42\u5934\u4f20\u9012<\/strong>\uff1aCloudflare Tunnel\u9ed8\u8ba4\u4f1a\u4fee\u6539<code>Host<\/code>\u5934\uff0c\u5bfc\u81f4WordPress\u65e0\u6cd5\u8bc6\u522b\u81ea\u8eab<\/li>\n\n\n\n<li><strong>HTTPS\u6df7\u5408\u5185\u5bb9<\/strong>\uff1aTunnel\u5f3a\u5236HTTPS\uff0c\u4f46WordPress\u5185\u90e8\u4ecd\u4f7f\u7528HTTP\u5730\u5740<\/li>\n\n\n\n<li><strong>REST API\u9a8c\u8bc1\u5931\u8d25<\/strong>\uff1aWordPress\u540e\u53f0\u64cd\u4f5c\u4f9d\u8d56<code>\/wp-json<\/code>\u63a5\u53e3\uff0c\u96a7\u9053\u914d\u7f6e\u9519\u8bef\u5bfc\u81f4\u963b\u65ad<\/li>\n\n\n\n<li><strong>IP\u5730\u5740\u4e0d\u4e00\u81f4<\/strong>\uff1aTunnel\u4f7f\u7528Cloudflare IP\uff0c\u4f46Nginx\u770b\u5230\u7684\u662f127.0.0.1<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udee0\ufe0f \u7ec8\u6781\u89e3\u51b3\u65b9\u6848\uff08\u5206\u6b65\u6267\u884c\uff09<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u7b2c\u4e00\u6b65\uff1a\u4fee\u590dWordPress\u5730\u5740\u8bbe\u7f6e<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. \u7f16\u8f91wp-config.php (\u5728define('WP_DEBUG')\u4e0a\u65b9\u6dfb\u52a0)\nsudo nano \/var\/www\/html\/blog\/wp-config.php<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/** \u5f3a\u5236HTTPS\u548c\u6b63\u786e\u4e3b\u673a\u5934 *\/\ndefine('WP_HOME', 'https:\/\/' . $_SERVER&#91;'HTTP_HOST']);\ndefine('WP_SITEURL', 'https:\/\/' . $_SERVER&#91;'HTTP_HOST']);\ndefine('FORCE_SSL_ADMIN', true);\n\n\/\/ \u5904\u7406Cloudflare\u4ee3\u7406IP\nif (isset($_SERVER&#91;'HTTP_CF_CONNECTING_IP'])) {\n    $_SERVER&#91;'REMOTE_ADDR'] = $_SERVER&#91;'HTTP_CF_CONNECTING_IP'];\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u7b2c\u4e8c\u6b65\uff1a\u4fee\u6b63Cloudflare Tunnel\u914d\u7f6e<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. \u7f16\u8f91Tunnel\u914d\u7f6e\u6587\u4ef6\nsudo nano \/etc\/cloudflared\/config.yml<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>tunnel: YOUR_TUNNEL_ID\ncredentials-file: \/root\/.cloudflared\/YOUR_TUNNEL_ID.json\ningress:\n  - hostname: yourdomain.com\n    service: http:\/\/localhost:80\n    originRequest:\n      noTLSVerify: true  # \u5173\u952e\u53c2\u6570\uff01\n      originServerName: yourdomain.com # \u4f20\u9012\u771f\u5b9e\u57df\u540d\n      httpHostHeader: yourdomain.com # \u4fee\u590dHost\u5934\n  - hostname: www.yourdomain.com\n    service: http:\/\/localhost:80\n    originRequest:\n      noTLSVerify: true\n      originServerName: www.yourdomain.com\n      httpHostHeader: www.yourdomain.com\n  - service: http_status:404<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u7b2c\u4e09\u6b65\uff1a\u4fee\u590dNginx\u914d\u7f6e\uff08\u5173\u952e\uff01\uff09<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/nginx\/sites-available\/blog<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n    # ... \u539f\u6709\u914d\u7f6e\u4fdd\u6301\u4e0d\u53d8 ...\n\n    location \/ {\n        # \u6dfb\u52a0\u4ee3\u7406\u5934\u8bc6\u522b\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        proxy_set_header X-Forwarded-Proto $scheme;\n        proxy_set_header Host $http_host; # \u4f20\u9012\u539f\u59cbHost\u5934\n\n        # WordPress\u91cd\u5199\u89c4\u5219\n        try_files $uri $uri\/ \/index.php?$args;\n    }\n\n    # \u5728PHP\u5904\u7406\u5757\u6dfb\u52a0\uff1a\n    location ~ \\.php$ {\n        # ... \u539f\u6709\u914d\u7f6e ...\n\n        # \u4fee\u590dREST API\u901a\u4fe1\n        fastcgi_param HTTPS \"on\";\n        fastcgi_param HTTP_X_FORWARDED_PROTO \"https\";\n        fastcgi_param HTTP_X_FORWARDED_FOR $proxy_add_x_forwarded_for;\n    }\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u7b2c\u56db\u6b65\uff1a\u91cd\u542f\u6240\u6709\u670d\u52a1<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart nginx php-fpm cloudflared\nsudo systemctl status cloudflared  # \u786e\u4fdd\u72b6\u6001\u6b63\u5e38<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u7b2c\u4e94\u6b65\uff1a\u4fee\u590dWordPress\u6570\u636e\u5e93<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u767b\u5f55MySQL\nsudo mysql -u root -p\n\n-- \u6267\u884c\u4fee\u590d\u547d\u4ee4\nUSE wordpress;\nUPDATE wp_options SET option_value = 'https:\/\/yourdomain.com' WHERE option_name IN ('siteurl', 'home');\nEXIT;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83e\uddea \u9a8c\u8bc1\u4fee\u590d\u6548\u679c<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6d4b\u8bd5REST API<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   curl -I https:\/\/yourdomain.com\/wp-json\/\n   # \u5e94\u8fd4\u56deHTTP\/2 200<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u624b\u52a8\u89e6\u53d1\u53d1\u5e03\u6d4b\u8bd5<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   # \u5728\u670d\u52a1\u5668\u6267\u884c\u5185\u90e8API\u6d4b\u8bd5\n   sudo -u www-data php -r \"require '\/var\/www\/html\/blog\/wp-load.php'; wp_remote_post( get_rest_url(null, 'wp\/v2\/posts') );\"<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u68c0\u67e5\u8c03\u8bd5\u65e5\u5fd7<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   tail -f \/var\/www\/html\/blog\/wp-content\/debug.log\n   # \u89c2\u5bdf\u53d1\u5e03\u65f6\u7684\u9519\u8bef\u4fe1\u606f<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u26a0\ufe0f \u82e5\u95ee\u9898\u4f9d\u7136\u5b58\u5728\uff1a\u7ec8\u6781\u6838\u6b66\u5668\u65b9\u6848<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. \u7981\u7528\u6240\u6709\u63d2\u4ef6\uff08\u901a\u8fc7\u6570\u636e\u5e93\uff09\nsudo mysql -u root -p wordpress -e \"UPDATE wp_options SET option_value = 'a:0:{}' WHERE option_name = 'active_plugins';\"\n\n# 2. \u91cd\u7f6e.htaccess\u89c4\u5219\ncd \/var\/www\/html\/blog\nsudo -u www-data cp -f wp-includes\/default-constants.php .htaccess\n\n# 3. \u4fee\u590d\u6587\u4ef6\u6240\u6709\u6743\nsudo chown -R www-data:www-data \/var\/www\/html\/blog\nsudo find \/var\/www\/html\/blog -type d -exec chmod 755 {} \\;\nsudo find \/var\/www\/html\/blog -type f -exec chmod 644 {} \\;\n\n# 4. \u91cd\u5efaNginx\u7f13\u5b58\nsudo rm -rf \/var\/cache\/nginx\/*\nsudo systemctl restart nginx<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd27 \u9884\u9632\u63aa\u65bd\uff08\u90e8\u7f72\u540e\u5fc5\u505a\uff09<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5b89\u88c5Must-Use\u63d2\u4ef6<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   sudo mkdir \/var\/www\/html\/blog\/wp-content\/mu-plugins\n   sudo nano \/var\/www\/html\/blog\/wp-content\/mu-plugins\/cloudflare_fix.php<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>   &lt;?php\n   \/\/ \u5f3a\u5236\u4fe1\u4efbCloudflare\u4ee3\u7406\n   if (isset($_SERVER&#91;'HTTP_CF_CONNECTING_IP'])) {\n       $_SERVER&#91;'REMOTE_ADDR'] = $_SERVER&#91;'HTTP_CF_CONNECTING_IP'];\n   }\n\n   \/\/ \u4fee\u590dREST API\u8ba4\u8bc1\n   add_filter('rest_authentication_errors', function($result) {\n       if (!empty($result)) return $result;\n       if (defined('REST_REQUEST') &amp;&amp; REST_REQUEST ) {\n           if (isset($_SERVER&#91;'HTTP_CF_RAY'])) {\n               return true; \/\/ \u4fe1\u4efbCloudflare\u8bf7\u6c42\n           }\n       }\n       return $result;\n   });<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u914d\u7f6eCloudflare\u9875\u9762\u89c4\u5219<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   URL: yourdomain.com\/wp-admin\/*\n   \u8bbe\u7f6e\uff1aSSL \u2192 \u5b8c\u5168\uff08\u4e25\u683c\uff09\n   \u8bbe\u7f6e\uff1a\u7f13\u5b58\u7ea7\u522b \u2192 \u7ed5\u8fc7<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u542f\u7528WordPress\u8c03\u8bd5\u65e5\u5fd7<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   \/\/ \u5728wp-config.php\u4e2d\u6dfb\u52a0\n   define('WP_DEBUG', true);\n   define('WP_DEBUG_LOG', true);\n   define('WP_DEBUG_DISPLAY', false);<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u901a\u8fc7\u8fd9\u5957\u7ec4\u5408\u62f3\uff0c99%\u7684&#8221;\u53d1\u5e03\u5931\u8d25&#8221;\u95ee\u9898\u90fd\u80fd\u89e3\u51b3\u3002\u5982\u679c\u4ecd\u6709\u95ee\u9898\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6536\u96c6\u8bca\u65ad\u6570\u636e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u751f\u6210\u8bca\u65ad\u62a5\u544a\nsudo cloudflared tunnel info YOUR_TUNNEL_ID &gt; tunnel.log\nsudo nginx -T &gt; nginx_config.log\nsudo tail -n 100 \/var\/log\/nginx\/error.log &gt; nginx_error.log\nsudo tail -n 100 \/var\/log\/cloudflared.log &gt; cloudflared.log<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u2014\u2014\u2014\u2014\u2013\u7cfb\u5217\u2461 Cloudfl &hellip; <a title=\"\u4e2a\u4eba\u7535\u8111\u90e8\u7f72\u535a\u5ba2\u7ad9\uff0c\u65e0\u9700\u516c\u7f51IP\uff0c\u65e0\u9700\u7aef\u53e3\u6620\u5c04\" class=\"hm-read-more\" href=\"https:\/\/alantu.top\/?p=54\"><span class=\"screen-reader-text\">\u4e2a\u4eba\u7535\u8111\u90e8\u7f72\u535a\u5ba2\u7ad9\uff0c\u65e0\u9700\u516c\u7f51IP\uff0c\u65e0\u9700\u7aef\u53e3\u6620\u5c04<\/span>Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":56,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-54","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-6"],"_links":{"self":[{"href":"https:\/\/alantu.top\/index.php?rest_route=\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alantu.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alantu.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alantu.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alantu.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=54"}],"version-history":[{"count":1,"href":"https:\/\/alantu.top\/index.php?rest_route=\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":55,"href":"https:\/\/alantu.top\/index.php?rest_route=\/wp\/v2\/posts\/54\/revisions\/55"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alantu.top\/index.php?rest_route=\/wp\/v2\/media\/56"}],"wp:attachment":[{"href":"https:\/\/alantu.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alantu.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alantu.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}