Mixed content explained and how to fix it
Mixed content is an HTTPS page that loads some resources, such as scripts, images or frames, over plain HTTP, which browsers block or upgrade because it weakens the page's security.
- Updated Nov 27, 2026
- Markdown
Find mixed content in the browser console, fix the links and stop a proxied app from generating http URLs.
- A site that loads over HTTPS
- Access to the app code or reverse proxy config
Mixed content happens when a page delivered over HTTPS asks for another resource, such as a script, image or iframe, over plain HTTP. The page itself is encrypted, but that one request is not, so anyone on the network can read or alter it. Browsers react by blocking or rewriting those requests. The typical symptoms are a missing image, a broken script, a missing padlock or a console full of warnings right after you switched a site to HTTPS.
How it works#
Every subresource on a page has a URL, and the scheme at the start of it (http or https) decides how it is fetched. On an HTTPS page, an http URL is a downgrade. Browsers split such requests into two groups:
- Active mixed content: scripts, stylesheets, iframes, fonts and fetch or XHR calls. These can rewrite the page, so a tampered response compromises everything. Browsers block them.
- Passive (display) mixed content: images, audio and video. These cannot run code, but can leak information or mislead users. Current browsers generally try to upgrade them to https automatically and may block them when no secure version exists.
Exact behavior varies by browser and version, so do not rely on the browser quietly fixing things. The reliable fix is to serve every resource over HTTPS.
Step 1: Find the offending URLs#
Open the page, open devtools (F12), and look at the Console. Mixed content messages name the exact URL that was blocked or upgraded. The Network tab, filtered by “http:”, also lists them. Search your own codebase and content too:
grep -rn "http://" templates/ static/ --include="*.html" --include="*.css" --include="*.js"The paths here are placeholders, use your project’s directories. Expect hits in HTML templates, CSS url() values, JavaScript constants, CMS content stored in a database, and third party embeds. Remember that XML namespaces such as http://www.w3.org/2000/svg are identifiers, not requests, and are not a problem.
Step 2: Fix the links#
Choose the first option that applies:
- Change the URL to https, and verify that the host actually serves it:
bash curl -sI https://cdn.example.net/library.js | head -n 1 - If the file is yours, serve it from your own site and use a relative or root-relative path such as
/assets/logo.png. Relative paths follow the page’s scheme. - Drop resources that only exist on http. If a third party has no https version, host a copy or remove the dependency.
Avoid protocol-relative URLs like //example.com/x.js in new code. They were a workaround for the http era and are now unneeded, since https works everywhere.
For content stored in a database (blog posts, CMS fields), run a careful search and replace on the stored URLs using your CMS tooling, and take a backup first.
Step 3: Add a safety net with CSP#
The upgrade-insecure-requests directive of Content-Security-Policy tells the browser to rewrite http subresource URLs to https before fetching them. In nginx:
add_header Content-Security-Policy "upgrade-insecure-requests" always;Reload with sudo nginx -t && sudo systemctl reload nginx. This is useful while you clean up old content, but it only works when the https version of the resource exists. It does not fix a missing file, and it does not change your stored data. Treat it as a bridge, not a replacement for fixing the URLs. If you already set a Content-Security-Policy header, add the directive to it rather than sending two headers.
Step 4: Fix apps behind a proxy#
A very common cause is an application behind a reverse proxy. The proxy terminates TLS and forwards plain HTTP to the app, so the app believes every request is insecure and builds absolute links, redirects and asset URLs starting with http://. The page then loads fine but pulls everything back over http.
The proxy has to tell the app what the original scheme was. In nginx:
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}Then the app must trust that header from the proxy. Each framework has a setting for it (often called trust proxy, proxy headers or forwarded allow ips). Check your framework documentation, and only trust the header from your own proxy, since clients can send fake ones. Without that setting, the header is ignored. See Nginx reverse proxy with certbot for a full proxy block and Redirect HTTP to HTTPS explained for redirect loops that have the same root cause.
Check it worked#
Reload the page with the console open and caching disabled in the Network tab. No mixed content messages should remain and the padlock should show a secure connection. From the command line, fetch the HTML and look for http references:
curl -s https://example.com/ | grep -o 'http://[^"'"'"' )]*' | sort -uAny URL that appears is a candidate to fix, other than harmless identifiers such as XML namespaces and plain links to other sites.
Edge cases and gotchas#
- Third party widgets: an old embed or analytics snippet hard codes http. Update the snippet or drop it.
- CSS and JS inside files:
url(http://...)inside a stylesheet or an API base URL in a script bundle is easy to miss in templates. - Redirect to http: an https URL that redirects to http still counts as an insecure load.
- Forms posting to http: a form whose action is http sends data in clear text, and browsers warn about it.
- WebSockets: use wss:// from an HTTPS page, since ws:// is blocked.
- HSTS makes it worse: once HSTS is on, any leftover http link to your own host is upgraded by the browser, which hides it from you until the policy expires.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
| Console says a script was blocked as mixed content | The page requests an http script URL | Change it to https or a relative path |
| Images missing, others fine | Passive content with no https version | Host the image yourself or fix the URL |
| App links and redirects use http | Proxy does not send X-Forwarded-Proto, or the app does not trust it | Add the header and enable the app’s proxy trust setting |
| Fixed templates but old posts still break | Stored content in the database has http URLs | Update stored content after a backup |
| upgrade-insecure-requests added but resource still fails | The https version of the resource does not exist | Fix the host or serve a copy |
| Redirect loop after enabling HTTPS | The app sees http and redirects to https again | Pass X-Forwarded-Proto and trust it |
Quick reference#
proxy_set_header X-Forwarded-Proto $scheme;
add_header Content-Security-Policy "upgrade-insecure-requests" always;curl -s https://example.com/ | grep -o 'http://[^"'"'"' )]*' | sort -uRelated lessons#
- Redirect HTTP to HTTPS explained: force the page itself onto HTTPS.
- HSTS explained: make browsers refuse plain HTTP to your host.
- Nginx reverse proxy with certbot: the proxy headers in a working config.
- HTTPS and Let’s Encrypt: the certificate that makes https URLs possible.
- What is a reverse proxy: why the app only sees plain HTTP.
Next#
Continue with TLS versions and ciphers in plain language.
Check what you learned
Frequently asked questions
What is mixed content?
It is an HTTPS page that pulls in resources over plain HTTP, such as images, scripts or iframes. The secure page is only as safe as its weakest request, so browsers restrict it.
What is the difference between active and passive mixed content?
Active content (scripts, stylesheets, iframes, fetch requests) can change the page and is blocked. Passive content (images, audio, video) is lower risk and browsers have moved toward upgrading or blocking it too.
How do I fix mixed content on my website?
Change the resource URLs to https or to relative paths, and make sure the resource exists on https. As a safety net you can add the upgrade-insecure-requests CSP directive.
Why does my app behind a reverse proxy create http links?
The proxy forwards requests to the app over HTTP, and the app builds absolute URLs from what it sees. Pass X-Forwarded-Proto from the proxy and configure the app to trust it.
Sources
Keep going: guides and tutorials
- Self-Hosted Static Site Hosting: Deploy a Folder With Levelrail Self-hosted static site hosting from a plain folder: one deploy command, _redirects, _headers and a custom 404 honored, plus a one command rollback.
- Deploy Next.js on a VPS With Docker, Git Push and HTTPS Deploy a Next.js app to your own VPS with Docker, a health check, HTTPS and rollback. Includes the NEXT_PUBLIC build trap that leaves variables empty.