Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

An HTTPS page is blocked from loading an insecure http:// resource

ErrorMixed Content: The page at 'https://example.com/' was loaded over HTTPS, but requested an insecure script 'http://example.com/app.js'. This request has been blocked; the content must be served over HTTPS.

Short answer

Your page came over HTTPS but something on it points at an http:// address, and the browser refuses the risky kinds (scripts, styles, frames, fetch calls). Find each insecure URL in the console, change it to https or a relative path, make the proxy tell the app the request was HTTPS, and keep upgrade-insecure-requests only as a safety net.

  • Applies to Current Chrome and Firefox, nginx 1.28, Express 5, Laravel 12 and 13
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List every http:// address in the HTML the server really returns. Compare it with what you see in the console: URLs that exist in the served HTML are hard-coded or generated by the app, while URLs that appear only after scripts run are built in JavaScript.

    curl -s https://example.com/ | grep -oE "(src|href|action|data-[a-z-]+)=[\"']http://[^\"']+" | sort -u
  2. 2Match what you see, then jump to its fix

    1. 1The curl command above lists addresses, and the browser blocks the script, stylesheet or frame they point at.Absolute http:// URLs are written into templates, content or the databaseFix
    2. 2Your templates use helpers like url() or req.protocol, nothing is hard-coded, and the generated links still start with http://.A reverse proxy ends HTTPS and the app thinks the request was plain HTTPFix
    3. 3The blocked URL is not in the served HTML; it appears in a fetch or XHR call, a CSS url(), an image on an IP address, or a widget you embed.A third-party file or API is only available over http, or is built in JavaScriptFix
    4. 4Hundreds of stored pages or years of old posts contain http:// links to your own site.Too many legacy URLs to fix at onceFix

What does the error look like?

  • Mixed Content: The page at 'https://example.com/' was loaded over HTTPS, but requested an insecure script 'http://example.com/app.js'. This request has been blocked; the content must be served over HTTPS.
  • Mixed Content: The page at 'https://example.com/' was loaded over HTTPS, but attempted to connect to the insecure endpoint 'http://api.example.com/items'. This request has been blocked.
  • Blocked loading mixed active content "http://example.com/style.css"

Cause 1 of 4

Absolute http:// URLs are written into templates, content or the database

1Check

Search the code, the templates and any stored content (CMS posts, settings, menu links) for your own http:// address. Old content written before the site moved to HTTPS is the usual source.

grep -rnE "http://(www\.)?example\.com" --include="*.php" --include="*.html" --include="*.js" --include="*.ts" --include="*.vue" --include="*.css" .
# database dump, if the content lives there
mysqldump mydb | grep -c "http://example.com"

2Fix

Use https:// for third-party resources and a root-relative path (/assets/app.js) for your own, so the scheme can never differ from the page. For stored content, rewrite the saved addresses with your CMS's own search-and-replace tool, taking a backup first.

<script src="/assets/app.js"></script>
<link rel="stylesheet" href="https://fonts.example.net/css">

3Verify

Reload with the console open; the Mixed Content lines are gone and the curl list is empty.

curl -s https://example.com/ | grep -cE "(src|href|action)=[\"']http://"   # expect 0

Confirmed by developer.mozilla.org

Did this fix it?

Cause 2 of 4

A reverse proxy ends HTTPS and the app thinks the request was plain HTTP

1Check

When nginx or a load balancer handles TLS and forwards plain HTTP to the app, the app sees http unless the proxy passes the original scheme and the app is told to trust that header. Print what the app sees.

grep -rn "X-Forwarded-Proto" /etc/nginx/
curl -s https://example.com/ | grep -oE "(href|src)=[\"']http://[^\"']+" | head

2Fix

Send the scheme from the proxy, and tell the framework to trust that proxy only. Never trust forwarded headers from the open internet.

# nginx
location / {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass http://127.0.0.1:3000;
}

// Express 5, proxy on the same machine
app.set('trust proxy', 'loopback')

// Laravel 12 and 13: bootstrap/app.php (use the proxy's real address)
->withMiddleware(function (Middleware $middleware): void {
    $middleware->trustProxies(at: ['10.0.0.0/8']);
})

3Verify

Generated links now start with https:// and req.protocol (or Laravel's url helper) reports https.

curl -s https://example.com/ | grep -cE "(href|src)=[\"']http://"   # expect 0

Confirmed by expressjs.com

Did this fix it?

Cause 3 of 4

A third-party file or API is only available over http, or is built in JavaScript

1Check

Passive content such as an image may be upgraded for you, but scripts, styles, frames and fetch calls are blocked, and a request to a bare IP address is not upgraded at all. Find the line in the code or the vendor's embed snippet that builds the URL.

grep -rnE "http://" src/ public/ --include="*.js" --include="*.ts" --include="*.css"
curl -sI https://api.vendor.example/ | head -n 1

2Fix

Switch to the provider's https address. If the provider has none, call it from your own server and serve the result over HTTPS, host a licensed copy yourself, or drop the dependency; sending users to an insecure resource is not an option.

// before
const res = await fetch('http://api.vendor.example/items')
// after
const res = await fetch('/api/items')   // your server calls the vendor and returns the data

3Verify

The request appears in the Network tab with an https URL and a 200 status.

grep -rnE "http://" src/ --include="*.js" --include="*.ts" | grep -v "localhost"

Confirmed by developer.mozilla.org

Did this fix it?

Cause 4 of 4

Too many legacy URLs to fix at once

1Check

Confirm that every host you reference also answers on HTTPS before you rely on an automatic upgrade; an upgraded request to a host without a certificate simply fails.

curl -sI https://cdn.example.com/ | head -n 1
curl -sI https://www.example.com/ | head -n 1

2Fix

Send the upgrade-insecure-requests directive. It makes the browser request every insecure URL over HTTPS, including scripts and frames. Add it to your existing policy rather than as a second header, and still correct the stored URLs over time.

# nginx, merged into your one policy
add_header Content-Security-Policy "upgrade-insecure-requests; default-src 'self'; script-src 'self'" always;

3Verify

The old http:// URLs are requested as https:// in the Network tab, with no Mixed Content errors.

curl -sI https://example.com/ | grep -i content-security-policy

Confirmed by developer.mozilla.org

Did this fix it?

How do I stop it coming back?

  • Write your own links as root-relative paths and third-party links as https from the start.
  • Pass the original scheme from every proxy and CDN to the app, and trust only the proxy addresses you run.
  • Test new pages with the console open and a search for http:// in the built output before deploy.
  • Redirect http to https for the whole site so nobody lands on the insecure version.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Security

The browser blocks a script because of your Content Security Policy

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

The page's Content-Security-Policy does not allow what it tried to run or load.

5 causes, each with a fix

Security

Keycloak blocks your single-page app with a CORS error

Request requires preflight, which is disallowed to follow cross-origin redirects.

Keycloak checks the Origin header of a browser call against the Web origins configured on that client and refuses it with 403 when it does not match.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.