All Deployment guides Deployment

How to Fix Mixed Content Warnings

Mixed content occurs when an HTTPS page loads sub-resources (images, scripts, stylesheets, fonts) over plain HTTP. Browsers block or warn about this because an insecure resource on a secure page undermines the security of the entire page.

Two types of mixed content

TypeExamplesBrowser behavior
Active (dangerous)Scripts, iframes, XHR, CSSBlocked by all browsers
Passive (display)Images, audio, videoShown with warning / degraded padlock

Active mixed content can modify the page (a man-in-the-middle could inject malicious JavaScript), so browsers block it completely. Passive mixed content is less dangerous but still degrades the security indicator.

How to find mixed content

Browser DevTools

  1. Open your site in Chrome/Firefox
  2. Open DevTools (F12) → Console tab
  3. Look for errors like:
    Mixed Content: The page at 'https://example.com' was loaded over HTTPS,
    but requested an insecure resource 'http://example.com/image.jpg'.

Command-line scan

curl -s https://yourdomain.com | grep -oP 'http://[^"'"'"'> ]+' | sort -u

Common causes and fixes

Hardcoded http:// URLs in HTML

<!-- Problem -->
<img src="http://example.com/logo.png">

<!-- Fix: use protocol-relative or HTTPS -->
<img src="https://example.com/logo.png">
<img src="//example.com/logo.png">
<img src="/logo.png">

Best practice: use relative paths (/images/logo.png) wherever possible.

Third-party resources still on HTTP

<!-- Problem -->
<script src="http://cdn.example.com/library.js"></script>

<!-- Fix -->
<script src="https://cdn.example.com/library.js"></script>

If the third party doesn’t support HTTPS, find an alternative provider or self-host the resource.

Database content with hardcoded URLs

WordPress and other CMSs store absolute URLs in the database. After migrating to HTTPS:

-- WordPress: update URLs in posts
UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://example.com', 'https://example.com');
UPDATE wp_options SET option_value = REPLACE(option_value, 'http://example.com', 'https://example.com');

Or use a plugin like Better Search Replace.

CSS with HTTP references

/* Problem */
background-image: url('http://example.com/bg.jpg');

/* Fix */
background-image: url('https://example.com/bg.jpg');
background-image: url('/images/bg.jpg');

Content Security Policy (CSP) — prevent future mixed content

Add a CSP header that blocks HTTP resources:

Nginx:

add_header Content-Security-Policy "upgrade-insecure-requests" always;

Apache:

Header always set Content-Security-Policy "upgrade-insecure-requests"

upgrade-insecure-requests tells browsers to automatically upgrade http:// requests to https:// — a safety net while you fix the source URLs.

Systematic fix: full-site audit

For a thorough cleanup, audit your entire site:

1. Crawl for HTTP references

# Scan all HTML files for http:// URLs
find /var/www/html -name '*.html' -o -name '*.php' | xargs grep -l 'http://' 2>/dev/null

# Scan CSS files
find /var/www/html -name '*.css' | xargs grep -l 'http://' 2>/dev/null

# Scan JavaScript files
find /var/www/html -name '*.js' | xargs grep -l 'http://' 2>/dev/null

2. Fix URLs by category

SourceFix method
Your own resourcesChange to relative paths (/images/logo.png)
CDN resourcesUpdate to https://cdn.example.com/...
Third-party scriptsUpdate URL or find HTTPS alternative
Inline CSSSearch-replace http://https://
Database content (WordPress)wp search-replace 'http://yourdomain.com' 'https://yourdomain.com'
Template/theme filesEdit source files directly

3. Verify with browser DevTools

After fixing, open each page → DevTools (F12) → Console tab. A clean page shows no mixed content warnings. The padlock icon should be solid (not broken or with a warning triangle).

4. Prevent future mixed content

Add this meta tag to your HTML <head> as a permanent safety net:

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

Or set it server-wide via Nginx/Apache config (shown above).

Types of content that commonly cause mixed content

Content typeWhere to checkExample
Images<img src="http://...">Uploaded images, avatars, logos
Scripts<script src="http://...">Analytics, chat widgets, ad scripts
Stylesheets<link href="http://...">External fonts, CSS frameworks
Fonts@font-face { src: url("http://...") }Google Fonts (usually fine), custom fonts
iframes<iframe src="http://...">Embedded videos, maps, widgets
XHR/Fetchfetch("http://...")API calls in JavaScript
Background imagesbackground-image: url("http://...")CSS backgrounds

Frequently asked questions

Will mixed content affect my SEO?

Not directly. Google crawls based on the page’s URL protocol, not sub-resources. However, if mixed content triggers browser warnings or blocks visible content, user experience degrades — which can indirectly hurt rankings through higher bounce rates.

Can I just use upgrade-insecure-requests and not fix the URLs?

It works as a stopgap, but fixing the source URLs is better. The CSP header depends on browser support (all modern browsers do, but some older clients don’t) and adds an extra header to every response.

My site has hundreds of hardcoded HTTP URLs. What’s the fastest fix?

Add upgrade-insecure-requests CSP header immediately (one line of server config). Then do a global search-and-replace in your codebase and database. Use grep -r 'http://' src/ to find hardcoded URLs in code.

Related articles

Deployment 2026-05-07
How to Redirect HTTP to HTTPS
Force all traffic to HTTPS with server-side redirects. Configuration examples for Nginx, Apache, and .htaccess with 301 permanent redirects.
Deployment 2026-05-08
How to Install an SSL Certificate on Nginx
Step-by-step guide to installing an SSL certificate on Nginx. Covers file upload, full server block config, TLS best practices, HTTP/2, HSTS, redirect setup, testing, and troubleshooting 6 common errors.
SSL & Certificates 2026-05-08
What is HTTPS? A Complete Guide
HTTPS encrypts the connection between your browser and a website. Learn how HTTPS works, the TLS handshake, HTTP vs HTTPS differences, performance impact, and how to enable it for free.
Get a free SSL certificate in your browser
No installation, no account. Your private key never leaves your device.
Get your certificate