Mixed content blocked after moving to HTTPS: causes and fixes
THE SHORT ANSWER
A mixed content error means the page loaded over HTTPS but asked for something over plain http://. Browsers block scripts, stylesheets, fetch() and XMLHttpRequest calls (Chrome: "This request has been blocked; the content must be served over HTTPS") and upgrade images, audio and video to https on their own. After a deploy the cause is usually one of three things: an http:// URL in your code or in an env var such as the API base URL, a backend behind a TLS-terminating proxy that thinks it runs on http and builds http:// links, or old http:// URLs saved in the database. Change the URLs to https:// or relative paths, make the framework trust X-Forwarded-Proto, and treat the upgrade-insecure-requests CSP directive as a stopgap.
What does the mixed content error look like?
Open DevTools on the broken page. Chrome prints one line per insecure request. These are from Chrome 158, loading an https page that asks for an http script, an API call and an image:
Mixed Content: The page at 'https://app.example.com/' was loaded over HTTPS, but requested an insecure script 'http://cdn.example.com/app.js'. This request has been blocked; the content must be served over HTTPS. Mixed Content: The page at 'https://app.example.com/' was loaded over HTTPS, but requested an insecure resource 'http://api.example.com/users'. This request has been blocked; the content must be served over HTTPS. Mixed Content: The page at 'https://app.example.com/' was loaded over HTTPS, but requested an insecure element 'http://cdn.example.com/logo.png'. This request was automatically upgraded to HTTPS, For more information see https://blog.chromium.org/2019/10/no-more-mixed-messages-about-https.html
An XMLHttpRequest (and so axios in the browser) reads “requested an insecure XMLHttpRequest endpoint”. In your own code, a blocked fetch() just rejects with TypeError: Failed to fetch, so the console line is the only place that says why.
MDN sorts mixed content into two groups:
| The browser does this | To these requests |
|---|---|
| Upgrades to https | <img src>, CSS images like background-image, <audio>, <video>, <source> |
| Blocks | Scripts, stylesheets, iframes, fetch(), XMLHttpRequest, web fonts, sendBeacon, images set through srcset or <picture> |
An upgrade only helps if the server answers on https. If it doesn't, the image is simply missing. And requests to a bare IP address are never upgraded: http://203.0.113.10/logo.png is blocked even as an image. A form whose action is an http:// URL gets its own warning, “contains a form that targets an insecure endpoint”.
Why does it only happen after deploy?
On your laptop the page itself is http://localhost, so an http:// API call isn't mixed with anything. Browsers also treat localhost and 127.0.0.1 as secure origins. Once the same code is served from an https:// domain, every http:// URL it loads becomes mixed content. The http:// URLs come from one of these places:
- A hardcoded URL, most often the API base URL in a
.envfile or in the code, or a script or font copied from an old tutorial. - A backend that generates absolute URLs from the request and believes the request was http, because a proxy ended TLS in front of it. Image URLs in API responses, pagination links and stylesheet links come out as http://.
- Content saved in the database with http:// URLs: uploaded file links, CMS posts, user avatars.
- An API or file server that has no HTTPS at all, such as a VPS reached by its IP and a port.
How do I find every http:// URL?
The console lists what the current page requested. Chrome's Issues tab in DevTools groups the same requests and says whether each was blocked or upgraded. Click through the pages that matter, since each page only reports its own requests.
Then search the source and the served HTML:
# In the repo: code and env files grep -rn "http://" src/ app/ resources/ templates/ .env* | grep -v localhost # In what the server sends curl -s https://app.example.com/ | grep -o 'http://[^"'\'' )]*' | sort -u
For a large site, a report-only policy makes the browser log every non-https load without blocking anything: send Content-Security-Policy-Report-Only: default-src https: for a while and watch the console, or add a reporting endpoint. It also flags data: URLs and inline scripts, so expect some noise.
How do I fix a hardcoded http:// API URL?
Point it at the https address. If the frontend and the API are served from the same domain, use a path without a host, such as /api/users, and the scheme can never be wrong:
# .env for the production build VITE_API_URL=https://api.example.com # or, in Next.js NEXT_PUBLIC_API_URL=https://api.example.com
VITE_ and NEXT_PUBLIC_ values are copied into the JavaScript at build time, so changing the variable does nothing until you rebuild and redeploy. The details are in Vite env variables undefined in production and NEXT_PUBLIC env vars undefined in production.
If the API only speaks http, for example a server reached as http://203.0.113.10:8000, no setting in the frontend can fix it. The browser won't send that request from an https page, and there is no certificate to upgrade to. Give the API a domain name with HTTPS, or host it on a platform that provides one. Once the API answers on a different origin over https, a CORS error may be the next thing you see; see CORS error after deploy.
Why does my backend generate http:// links behind a proxy?
Frameworks build absolute URLs from the current request. Laravel's docs say the url helper “will automatically use the scheme (HTTP or HTTPS) and host from the current request”. Django's build_absolute_uri() “will always generate an absolute URI with the same scheme the current request has”. Express builds req.protocol from the connection.
Behind a proxy that ends HTTPS, the connection your app sees is plain http. The original scheme is in the X-Forwarded-Proto: https header, and frameworks ignore that header until you say the proxy is trusted. The same missing setting causes redirect loops when the app also forces HTTPS; that side is covered in ERR_TOO_MANY_REDIRECTS behind a proxy. Here is the setting for each stack, and where the wrong links usually show up.
Laravel. A page with no CSS after deploy is the classic sign: asset(), and so the @vite tags, produce http:// links that the browser blocks. Trust the proxy in bootstrap/app.php:
->withMiddleware(function (Middleware $middleware): void {
$middleware->trustProxies(at: '*');
})If you can't trust the proxy headers, force the scheme instead, in AppServiceProvider::boot(). URL::forceHttps() exists from Laravel 11; older versions have URL::forceScheme('https'):
use Illuminate\Support\Facades\URL;
public function boot(): void
{
URL::forceHttps($this->app->isProduction());
}Set APP_URL to the https address as well. Artisan commands and queued jobs have no request to read the scheme from and use it instead.
Django. Image URLs in API responses come from build_absolute_uri(). Tell Django which header carries the scheme, and request.is_secure() and every absolute URL follow it:
# settings.py
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")The same line fixes the CSRF origin errors in Django DisallowedHost and CSRF errors behind a proxy.
Express. Express's docs say that when trust proxy is on, req.protocol “will use the value of the X-Forwarded-Proto header field if present”:
app.set("trust proxy", 1);
app.get("/api/photos/:id", (req, res) => {
const base = `${req.protocol}://${req.get("host")}`; // https://... now
res.json({ url: `${base}/uploads/${req.params.id}.jpg` });
});FastAPI and Starlette. request.url_for(), including the static file links in Jinja templates, uses the scheme Uvicorn reports. Uvicorn only applies X-Forwarded-Proto from the addresses in FORWARDED_ALLOW_IPS, so set it to the proxy's address, or to * when the proxy is the only way in.
Rails. config.assume_ssl = true in production.rb makes Rails treat every request as https, so its URL helpers produce https links.
What about http:// URLs saved in the database?
Code changes don't touch rows that already hold http://. Find them, then rewrite them in one statement. Take a backup first. replace() works the same in Postgres and MySQL:
-- see what you're about to change SELECT id, image_url FROM products WHERE image_url LIKE 'http://%'; UPDATE products SET image_url = replace(image_url, 'http://api.example.com/', 'https://api.example.com/') WHERE image_url LIKE 'http://api.example.com/%';
Better still, store a path (/uploads/42.jpg) or a storage key and build the full URL when you send the response. Then a change of domain or scheme never needs a migration.
Should I just add upgrade-insecure-requests?
It works as a stopgap. The directive tells the browser to rewrite every http:// subresource on the page to https:// before requesting it, your own and third-party ones alike, including the requests it would otherwise block. Send it as a header, or as a meta tag in the page's <head>:
Content-Security-Policy: upgrade-insecure-requests <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
Know what it doesn't do:
- MDN: “if the requested resource is not actually available via HTTPS, the request will fail without any fallback to HTTP.” An http-only API stays broken.
- It changes the URL, nothing else. In our test, a blocked
fetch()to another origin went out over https once the header was set, and then failed with a CORS error because that API didn't allow the page's origin. - Links that navigate to other sites are not upgraded.
- It doesn't replace
Strict-Transport-Security, which stops browsers from ever loading your own site over http.
If you use Helmet in Express, its default Content-Security-Policy already ends with upgrade-insecure-requests. Fix the URLs at the source anyway, so the page doesn't depend on the header being there.
What happens on EthioDeploy?
Every project gets HTTPS on its ethiodeploy.app address and on custom domains. Port 80 only redirects to https. HTTPS ends at our proxy, and your app receives plain http with X-Forwarded-Proto: https, which the proxy sets itself and never passes through from a visitor. So the trust settings above are safe to turn on, and they're what you need for correct links:
- Laravel:
trustProxies(at: '*'). - Django:
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https"). - Express and NestJS:
app.set("trust proxy", 1). - FastAPI and other Uvicorn apps: the env var
FORWARDED_ALLOW_IPS=*. - Rails:
config.assume_ssl = true.
We don't add a Content-Security-Policy or HSTS header to your app's responses, so nothing is upgraded for you. If the frontend and the API are separate projects, both have https addresses: put the API's https:// URL in the frontend's env var and redeploy the frontend so the build picks it up. Framework setup is in the Laravel, Django, Express and FastAPI guides.
Questions
The page was loaded over HTTPS and tried to load a script, stylesheet, iframe, font or API call over plain http://. Browsers block those. Change the URL to https:// (or a relative path), or serve the resource over HTTPS.
Browsers upgrade http:// images, audio and video to https:// on their own, and block fetch(), XMLHttpRequest, scripts and stylesheets. If the image server also answers on https, images keep working while the API calls fail.
Behind a proxy that ends HTTPS, Laravel sees an http request and asset() and the @vite tags produce http:// links, which the browser blocks. Trust the proxy with trustProxies(at: '*') in bootstrap/app.php, or call URL::forceHttps() in AppServiceProvider, and set APP_URL to the https address.
It rewrites http:// subresource URLs to https:// before the browser requests them. That works when the resource exists on https. If it doesn't, the request fails with no fallback, and the directive doesn't fix CORS or replace HSTS. Use it as a stopgap while you fix the URLs.
Not from the browser. Browsers block fetch() and XMLHttpRequest to http:// from an https page, and requests to a bare IP are never upgraded. Put the API behind a domain with HTTPS, or call it from your own server instead of the browser.
Sources
Checked on November 29, 2026:
Push a repo. Get a URL.
Start freeJoin the EthioDeploy Telegram
Release notes as they ship, plus deploy help from the team and other developers.