Skip to content
>_VibeUnstuck

Mixed Content: blocked an insecure request on HTTPS

Last verified:

The fix

The deployed site is HTTPS. The browser blocked a request the page made to an http:// or ws:// URL.

  1. 1

    Copy the blocked URL from the console

    The message includes the http:// or ws:// address. Search the repo for that host, not for the words Mixed Content. It is often a default in .env, a NEXT_PUBLIC_ or VITE_ value, or a string the model hardcoded next to fetch. Change that one URL to https:// or wss://. If the server does not answer on HTTPS, the browser is right to refuse. Fix the server or pick a host that has a certificate. Do not proxy the user's browser at an http:// API to get around the block.

  2. 2

    Rebuild after you change a public env var

    NEXT_PUBLIC_ and VITE_ values are inlined at build time. Editing the host dashboard does not change the deployment that already shipped the http:// string. Set the value to the https:// URL and redeploy. A Supabase project URL from the dashboard is https://<project-ref>.supabase.co. If the console shows http://127.0.0.1 or http://localhost, the deployed bundle is still pointed at your laptop.

  3. 3

    Do not confuse it with CORS

    CORS says blocked by CORS policy and names Access-Control-Allow-Origin. Mixed content names an insecure URL and says the content must be served over HTTPS. Adding CORS headers, a Vite proxy, or Access-Control-Allow-Origin: * does not make the browser fetch http:// from an HTTPS page. A proxy in the dev server also does not exist on the deployed site.

  4. 4

    Upgrade is a migration aid, not the fix for one URL

    MDN's Content-Security-Policy: upgrade-insecure-requests rewrites HTTP URLs to HTTPS before the mixed-content check. Use it only when a lot of legacy URLs should already work on HTTPS. If that host has no certificate, the rewritten request fails instead of being blocked, and you still have to change the URL. Do not add the CSP and leave http://localhost in the production bundle.

Why it happens

MDN describes mixed content as a page loaded over HTTPS that then asks for something over HTTP. Browsers upgrade image, audio, and video requests from http:// to https://. They block the rest: scripts, stylesheets, fonts, fetch, and XMLHttpRequest. A secure page that opens ws:// is the same class of problem. The console names the page URL and the blocked URL. The request never reaches your API, so a CORS header on the server cannot help.

Localhost hides it. http://localhost:3000 calling http://localhost:54321 is not mixed content, because the page itself is not a secure origin. The Vercel or Netlify URL is HTTPS. A generated client that still has http:// in an API base, a Supabase URL, an image host, or a webhook target fails only after deploy. An address written as an IP (http://1.2.3.4/...) is not upgraded even for images. MDN says those requests are blocked.

The next error you'll probably hit

Once this is fixed, the usual follow-up is has been blocked by CORS policy. This request has been blocked by CORS policy. The API sent no Access-Control-Allow-Origin for this page. Allow that origin on your server, or proxy it.

Prompt to paste back into your AI tool

Paste this above the error.

The deployed HTTPS site logs: Mixed Content: The page at '<page url>' was loaded over HTTPS, but requested an insecure resource '<blocked url>'. This request has been blocked; the content must be served over HTTPS.

Do not add Access-Control-Allow-Origin. Do not set the production API URL to http://localhost. Do not add upgrade-insecure-requests and leave the http:// URL in the code.

1. Find the string that becomes <blocked url>. Change http:// to https:// or ws:// to wss://. If that host has no TLS, say so and stop.
2. If the value comes from NEXT_PUBLIC_ or VITE_, tell me to set the https URL in the host and redeploy. Those are inlined at build time.
3. If the blocked host is localhost or 127.0.0.1, the deployed bundle is using a local URL. Point it at the hosted https URL.
4. Change only that URL. Do not rewrite the fetch layer.

Common questions

+The image still appears, but the console mentions mixed content. Did the browser block it?

MDN says browsers upgrade image, audio, and video requests to HTTPS, and block other types. An upgraded image can still load. A blocked fetch will not. If the upgraded image 404s, the file is not available on HTTPS and the src still has to change.

+It works in npm run dev and fails on the Vercel URL. Is the API down?

Usually no. Dev is an HTTP origin, so the browser allows the HTTP API. The deployed page is HTTPS, so the same http:// call is mixed content. Read the blocked URL in the console.

Related errors