启用Cloudflare SSL后Google站长工具抓取返回301错误求助
Let's dig into why Google's crawler is hitting a 301 when trying to access your HTTPS www site—even after you moved redirect logic to Nginx and cleared Cloudflare page rules. Here are the most likely issues and how to fix them:
Cloudflare SSL/TLS Mode Misconfiguration
Cloudflare's SSL mode can silently cause redirects even without page rules. If you're using Flexible mode, Cloudflare communicates with your Nginx server over HTTP, but if your Nginx is set to force HTTPS, this creates a loop that triggers unexpected 301s.- Fix: Head to Cloudflare → Your Domain → SSL/TLS → Overview, and switch to Full or Full (Strict) mode. Full Strict is ideal here, just make sure your Nginx is using a valid Cloudflare Origin CA certificate or a trusted third-party cert (otherwise you'll hit a 525 error).
Broken Nginx Redirect Rules
It's easy to mess up server block order or regex in Nginx, which can lead to your HTTPS www site redirecting itself. Let's verify your config:- First, ensure your HTTP server block redirects all traffic to HTTPS www:
server { listen 80; server_name your-domain.com www.your-domain.com; return 301 https://www.your-domain.com$request_uri; } - Then, your HTTPS server block for
www.your-domain.comshould not include any extra redirects—it should just serve your content:server { listen 443 ssl; server_name www.your-domain.com; ssl_certificate /path/to/your/cloudflare-origin-cert.pem; ssl_certificate_key /path/to/your/cloudflare-origin-key.pem; root /var/www/your-site-root; index index.html; location / { try_files $uri $uri/ =404; } } - If you have an HTTPS server block for
your-domain.com(non-www), make it redirect to www:server { listen 443 ssl; server_name your-domain.com; return 301 https://www.your-domain.com$request_uri; } - Test your config with
sudo nginx -tto catch syntax errors, then restart Nginx withsudo systemctl restart nginx.
- First, ensure your HTTP server block redirects all traffic to HTTPS www:
Stale Cloudflare Cache
Cloudflare might still be serving cached redirects even after you deleted page rules. Clear the entire cache to be sure:- Go to Cloudflare → Your Domain → Caching → Configuration → Purge Cache → Select "Purge Everything" and confirm. Wait 5-10 minutes for the cache to refresh before retesting.
- Also, double-check the "Always Use HTTPS" setting under SSL/TLS → Edge Certificates. While this is generally recommended, you can temporarily disable it to see if it's conflicting with your Nginx rules (remember to re-enable it later if that's not the issue).
Google Crawler Cache
Google's crawler might have cached the old 301 response, even if you've fixed the issue now. Force a fresh crawl:- In Google Search Console, open your HTTPS www property → Go to the URL Inspection tool → Enter your homepage URL → Click "Test Live URL". This will make Google fetch the latest version of your site. If the test returns a 200 OK, the crawler will update its cache over time.
Hidden Redirects from Your App or .htaccess
Don't overlook redirects coming from your application itself (e.g., WordPress site settings) or leftover.htaccessfiles (if you previously used Apache):- For WordPress: Go to Settings → General, and confirm both "WordPress Address (URL)" and "Site Address (URL)" are set to
https://www.your-domain.com. - Check your site root for a
.htaccessfile—if it exists, comment out any 301 redirect rules and test again.
- For WordPress: Go to Settings → General, and confirm both "WordPress Address (URL)" and "Site Address (URL)" are set to
Cloudflare DNS/Proxy Status
Ensure your domain's A/AAAA records in Cloudflare are set to the orange cloud (proxy enabled)—if they're gray (DNS only), Cloudflare's settings won't apply, but this is less likely since you were using Cloudflare before. Also, double-check that all page rules are truly deleted (sometimes they can hide in the "Inactive" tab).
Start with the first two steps (Cloudflare SSL mode and Nginx config)—those are the most common culprits. If none of these work, use curl -v https://www.your-domain.com to inspect the response headers and see exactly where the 301 is coming from (look for the Location header to see where it's redirecting to).
内容的提问来源于stack exchange,提问作者Hossein Sadeghi

