HTTPS混合内容问题求助:IP搭建的WordPress staging站加载不安全图片
Hey there, let's get this mixed content issue sorted out. The problem here is straightforward: your staging site (running on HTTPS with that self-signed cert) is trying to load images from Domain1 over HTTP, even though Domain1 has a valid Let's Encrypt SSL certificate. Browsers block insecure resources on secure pages, hence the warning. Here are the steps to fix this:
1. Update Image URLs in Your WordPress Content
Chances are, your posts, pages, or media library entries are still referencing images using http://img.{domain_name_1}.com instead of the HTTPS version.
SQL Search & Replace (Fastest Method)
Head into phpMyAdmin (you mentioned you have it set up), select your WordPress database, and run these two queries to swap all HTTP references to HTTPS for your image domain:UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://img.{domain_name_1}.com', 'https://img.{domain_name_1}.com'); UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'http://img.{domain_name_1}.com', 'https://img.{domain_name_1}.com');Pro tip: Replace
wp_with your actual table prefix if you changed it during WordPress installation.Plugin-Based Approach (No SQL Needed)
If you're not comfortable with SQL, grab the "Better Search Replace" plugin from the WordPress plugin directory. Enterhttp://img.{domain_name_1}.comas the search term andhttps://img.{domain_name_1}.comas the replace term, select all relevant tables, and hit "Run Replace". It'll handle updating all instances across your content and metadata.
2. Force HTTPS Redirects on Domain1
Since Domain1 already has Let's Encrypt SSL, let's make sure every request to it goes over HTTPS. Edit the .htaccess file in the root folder of Domain1 and add these lines:
RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This permanent redirect will automatically send any HTTP image requests to the HTTPS version, so even if old URLs are still floating around, they'll get fixed on the fly.
3. Configure WordPress to Recognize HTTPS for Your Staging Site
Even though your staging site uses HTTPS with an IP address, WordPress might not be fully aware of it, leading to incorrect URL generation.
- Go to Settings > General in your WordPress admin. Set both "WordPress Address (URL)" and "Site Address (URL)" to
https://99.999.999.999(your staging IP with HTTPS). - Install the "Really Simple SSL" plugin. It'll automatically detect your SSL setup and rewrite all resource URLs (including those from Domain1) to HTTPS, eliminating mixed content issues without manual edits.
4. Clear All Caches
Don't forget to clear your WordPress cache (if you're using a caching plugin like WP Rocket or W3 Total Cache) and your browser cache. Old HTTP image URLs might be cached, so clearing these ensures you see the fixed HTTPS requests immediately.
Quick Recap
The core issue is insecure HTTP requests for images on a secure HTTPS page. By updating the URLs in your content, redirecting HTTP to HTTPS on Domain1, or forcing WordPress to use HTTPS for all resources, you'll resolve the mixed content warning.
内容的提问来源于stack exchange,提问作者R99

