Troubleshooting guide
Mixed content errors: how to find and fix them
Mixed content means an HTTPS page tried to load something over plain HTTP. Browsers block scripts outright and upgrade or warn for images.
3 min read9 sectionsUpdated
On this page
What mixed content is
An encrypted page that pulls in unencrypted resources undermines its own protection, since an attacker could alter the script in transit. Browsers therefore block active content such as scripts, iframes and stylesheets. Images, audio and video are upgraded to HTTPS automatically where possible, and blocked if that fails.
Diagnose it
Open DevTools, then the Console, and filter by "Mixed Content". Every blocked resource is listed with its URL. To scan the HTML of a page from the command line:
# http:// references in src or href
curl -s https://example.com/ | grep -oE '(src|href)="http://[^"]+' | sort -u
# WordPress: count stored http links (requires WP-CLI)
wp db query "SELECT COUNT(*) FROM wp_posts WHERE post_content LIKE '%http://example.com%'"
# Does the app know it is behind TLS?
curl -sI https://example.com/ | grep -i locationFixes
Replace the URLs at the source. On WordPress, run wp search-replace 'http://example.com' 'https://example.com' after a backup. Update API URLs in configuration. Pass X-Forwarded-Proto from the proxy so the application generates HTTPS links. Then add this response header as a safety net:
Content-Security-Policy: upgrade-insecure-requests
Finally, enable HSTS once everything works over HTTPS.
Catch it automatically
Blocked scripts rarely return an error status, so a normal uptime check will not see them. Real-user monitoring catches the resulting JavaScript errors in actual browsers, and a browser check can fail when a key element does not appear on the page.
Does mixed content hurt SEO?
Indirectly. Google prefers secure pages, and broken scripts or images damage user experience, which matters more than the warning.
Is upgrade-insecure-requests enough?
It fixes most cases, but only if the resource is available over HTTPS. Fix the source URLs as well.
Why is an image blocked when others load?
The browser tried to upgrade it to HTTPS, and that server does not offer it.
Related reading
- 422 Unprocessable Entity: how to fix it: Fix 422 Unprocessable Entity (Unprocessable Content): validation errors in APIs and forms, CSRF tokens in Rails and Laravel, and how to read the error body.
- ERR_CONTENT_DECODING_FAILED: how to fix it: Fix ERR_CONTENT_DECODING_FAILED: wrong Content-Encoding headers, double gzip compression, broken Brotli, PHP output buffering and proxies, with tests.
- 404 Not Found: how to find and fix broken pages: Find and fix 404 errors: broken internal links, moved pages, case-sensitive paths and soft 404s, with commands and advice on what actually affects SEO.
- 500 Internal Server Error: how to find the cause: A 500 error means your code failed. Find the exception behind it fast with logs, traces and error tracking, and learn how to prevent repeats.
- ENOTFOUND getaddrinfo: how to fix DNS errors in Node.js: Fix getaddrinfo ENOTFOUND and EAI_AGAIN in Node.js: wrong hostnames, a URL passed as host, container DNS and thread pool exhaustion, with test commands.
- Goroutine leaks in Go: how to find and fix them: Find and fix goroutine leaks in Go: read pprof goroutine profiles, spot blocked channels and missing context cancellation, and use goleak in your tests.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.