# Mixed Content: the page was loaded over HTTPS, but requested an insecure resource — fix after deploy

> Mixed Content: The page at 'https://…' was loaded over HTTPS, but requested an insecure resource 'http://…'. This request has been blocked means your HTTPS page asked for a script, stylesheet or API call over plain http://, and the browser refused. After a deploy the usual reasons are an API address with http:// baked into the frontend build, or a backend behind an HTTPS proxy that builds its URLs with http://. Use https:// or relative URLs, rebuild, and make the backend trust its proxy.

Source: https://livops.dev/en/guides/error-mixed-content-blocked

By Livops team, the people who build and run Livops. Updated 1 December 2026.

What the browser console shows, on a page that loads but stays empty or half-working after the deploy[2]:

```text
Mixed Content: The page at 'https://shop.example.com/' was loaded over HTTPS, but requested an insecure resource 'http://api.example.com/products'. This request has been blocked; the content must be served over HTTPS.
```

The word after "insecure" tells you what was asked for: `resource` for `fetch()`, `XMLHttpRequest endpoint` for Axios and other XHR clients, `script`, `stylesheet`, `frame` or `font`[2]. Images get a softer line, ending in "This request was automatically upgraded to HTTPS"[2].

This page explains which requests a browser blocks and which it upgrades, finds the `http://` address in the four places it usually comes from after a deploy, gives the fix for Vite, Laravel, Django and Express, and shows where the `upgrade-insecure-requests` header helps and where it does not.

## What does the error mean?

Mixed content is a page loaded securely that fetches resources over HTTP or another insecure protocol[1]. Browsers sort it in two groups[1]:

- **Upgradable: images, audio and video.** The browser changes the address from `http` to `https` by itself, and the server answers with the file or with "not found". A request whose host is an IP address rather than a domain name is blocked instead of upgraded.
- **Blockable: everything else**, including `<script src>`, stylesheets in `<link href>`, `<iframe src>`, `fetch()` and `XMLHttpRequest`. These are blocked.

So the page loads, but its JavaScript bundle, its styles or its API calls do not, and the app looks broken without a server error anywhere.

Why you never saw it locally: the page was `http://localhost`, nothing on it was secure, so nothing was mixed. And content from loopback addresses such as `http://127.0.0.1/` or `http://localhost/` counts as secure even on an HTTPS page[1]. Only the deployed site, on `https://`, shows it.

The fix MDN gives: serve everything over HTTPS, make references to your own domain relative or `https://`, and use the HTTPS version of resources on other sites[1].

## Causes, most common first

### 1. The API address is baked into the frontend build

The frontend reads its API address from a variable, and in production that variable says `http://`. In Vite, `import.meta.env` values are statically replaced at build time, and only variables prefixed with `VITE_` reach client code[4]:

```js
const api = import.meta.env.VITE_API_URL; // the value is written into the bundle at build time
fetch(`${api}/products`);
```

Changing the variable on a running site changes nothing: the old address is already in the built files. **Fix: set the variable to `https://` and build again.**

```sh
VITE_API_URL=https://api.example.com
```

Two traps. `vite build` reads `.env.production` if there is one[4], so an `http://` value committed there comes along. And variables already set where Vite runs have the highest priority and are not overwritten by `.env` files[4], so an old value in the build environment beats a fixed `.env.production`. Keep secrets out of `VITE_` variables altogether: they end up in the bundle[4].

If the API is on the same domain, the simplest fix is no domain at all: `fetch("/api/products")` follows the page's own scheme.

### 2. A hard-coded http:// in the code or the HTML

A script tag for a CDN, a font, a widget, an `<iframe>` for a map, or an API base written straight into the code. Find every one in the build output:

```sh
npm run build
grep -rnoE "http://[^\"' )]+" dist/ | grep -v "www.w3.org"
```

The `www.w3.org` lines are SVG and XML namespace names, not requests; everything else is a candidate. Change your own domain's addresses to relative paths, and other sites' addresses to their `https://` versions[1]. If a third party has no HTTPS version, it cannot be loaded on an HTTPS page; host the file yourself or replace it.

### 3. The backend builds its URLs with http:// behind the HTTPS proxy

The page and its first request are fine, but the API answers with absolute URLs that start with `http://`: image URLs, `next` links in paginated responses, file download links. The browser then blocks those.

The reason is the proxy in front of the app. It takes the visitor's HTTPS connection and passes the request on over plain HTTP, so the framework believes the request was HTTP and builds URLs to match. Each framework has a setting that makes it read the original scheme from the proxy's header, and each comes with the same caution: trust the header only if your proxy sets it and a visitor cannot forge it.

**Laravel.** Behind a load balancer that terminates TLS, Laravel sometimes does not generate HTTPS links, because traffic arrives on port 80[5]. Trust the proxy in `bootstrap/app.php`; `*` trusts all of them when you do not know their addresses[5]:

```php
->withMiddleware(function (Middleware $middleware): void {
    $middleware->trustProxies(at: '*');
})
```

Laravel builds URLs with the request's own scheme unless one is forced, and `URL::forceScheme('https')` or `URL::forceHttps()` forces HTTPS for every generated URL[6]. The proxy setting is the better fix, because it also makes the request itself count as secure.

**Django.** Behind a proxy that talks plain HTTP to Django, `is_secure()` returns `False` even for requests the visitor made over HTTPS[7], and `build_absolute_uri()` always uses the scheme of the current request[8]. The setting:

```python
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
```

Django's warning is strict: set it only if the app is behind a proxy, the proxy strips `X-Forwarded-Proto` from all incoming requests, and sets it only for requests that came in over HTTPS; otherwise keep it `None`[7].

**Express.** `req.protocol` uses the `X-Forwarded-Proto` header only when the `trust proxy` setting is not false[10], and `req.secure` is `req.protocol === 'https'`[10]. By default it is false, and the app is understood as facing the client directly[9]:

```js
app.set("trust proxy", 1); // trust the first proxy in front of the app

app.get("/products", (req, res) => {
  const base = `${req.protocol}://${req.hostname}`; // https once the proxy is trusted
  // ...
});
```

A number means the addresses at most that many hops away[9]. If you set it to `true`, the last trusted proxy must remove or overwrite `X-Forwarded-For`, `X-Forwarded-Host` and `X-Forwarded-Proto`, or a client could supply any value[9].

The same mistake shows up in the HTML a server renders: a form action or a stylesheet link built with `http://`. With Laravel the visible symptom is often a [419 Page Expired](https://livops.dev/en/guides/error-laravel-419-page-expired) on every form, because the form posts to `http://` and the secure session cookie stays behind.

### 4. Old http:// URLs stored in the database

A CMS, a blog or a shop that ran on `http://` before stores full image URLs inside its content. The images may still show, because browsers upgrade them[1], as long as the same address answers over HTTPS; embedded scripts and frames in that content are blocked. Fix the data, not the template. Back up first, then for each table and column that holds content:

```sql
UPDATE posts
SET body = REPLACE(body, 'http://shop.example.com/', 'https://shop.example.com/');
```

For new content, store paths such as `/uploads/photo.jpg` rather than full URLs.

## A stopgap: upgrade-insecure-requests

One header tells the browser to treat all of the page's `http://` URLs as if they were `https://`[3]:

```text
Content-Security-Policy: upgrade-insecure-requests
```

or, if you cannot set headers, in the page's `<head>`[3]:

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

It is meant for sites with many legacy `http://` URLs that still need rewriting[3]. What it does not do:

- **It has no fallback.** If the resource is not available over HTTPS, the request fails[3].
- **Links to other sites stay as they are.** Subresource requests are upgraded, first-party and third-party alike, but navigation to third-party addresses is not[3].
- **It does not replace HSTS**, which you still want against SSL stripping[3].

Use it to stop the bleeding while you fix the addresses in causes 1 to 4, not instead of fixing them.

## How to confirm the fix

1. Open the deployed site with the browser's developer tools on the **Console** tab and reload. No line may start with `Mixed Content`.
2. On the **Network** tab, filter by `http://`; no request should be left.
3. Check what the API returns, not only the page:

   ```sh
   curl -s https://api.example.com/products | grep -o '"http://[^"]*"' | head
   ```

   An empty result means the backend builds `https://` URLs. Any line is cause 3 or 4.

## On Livops

- **Every address is HTTPS.** Every project gets a `<name>.livops.app` address with HTTPS, and a domain you connect gets its certificate automatically as soon as it is live. Nothing to configure; what is left is the `http://` addresses inside your code, variables and data.
- **In the docs too.** Livops's docs on a page that opens blank cover this case: on an HTTPS page the browser blocks scripts over `http://`; use `https://` or a path on the same site. See [The page loads files over http://](https://livops.dev/en/docs/error-output#insecure).
- **Static site variables are build variables.** A static site reads `VITE_*`, `NEXT_PUBLIC_*` and similar variables at build time, and they are baked into the files, visible to anyone. Fix `VITE_API_URL` in the service's **Variables** and deploy again: new values take effect on the next deploy. When a staging release of a static site is promoted, it is rebuilt from the same commit with production's variables, so check the production value too.
- **Not `localhost` either.** An API address of `http://localhost:8000` is the visitor's own computer once deployed; see [The frontend calls localhost](https://livops.dev/en/docs/error-output#localhost-api).
- **The CSP header on a static site** goes in a `_headers` file at the root of the build output (`public/_headers` becomes `dist/_headers`):

  ```text
  /*
    Content-Security-Policy: upgrade-insecure-requests
  ```

  For a web app, send the header from the app itself.
- **Proxy settings only on evidence.** Before you set `trustProxies`, `SECURE_PROXY_SSL_HEADER` or `trust proxy`, check which header reaches your app: log the request headers once from a test route.

Forms failing after the same deploy: [419 Page Expired in Laravel](https://livops.dev/en/guides/error-laravel-419-page-expired), [Django CSRF verification failed](https://livops.dev/en/guides/error-django-csrf-verification-failed). A static site that answers 404 on refresh: [404 on page refresh in a React or Vue app](https://livops.dev/en/guides/error-spa-404-on-refresh).

## Questions

**Why does it work locally and break after deploy?**

Locally the page is served over http://localhost, so nothing on it is mixed, and browsers treat loopback addresses such as localhost as secure anyway. In production the page is HTTPS, and any http:// address it still uses, from a build variable, a hard-coded link or the backend's own URLs, is now blocked.

**Why are some images still shown while my API calls are blocked?**

Browsers upgrade images, audio and video from http:// to https:// by themselves, and block everything else that is mixed: scripts, stylesheets, frames, fetch and XMLHttpRequest. An image shows if the same address works over https; it fails if it does not, or if its host is an IP address.

**I changed VITE_API_URL to https but the site still calls http. Why?**

Vite replaces import.meta.env values in the code at build time, so the old address is written into the built files. Change the variable where the build runs and build again; a restart is not enough. Also check that no other variable or .env file with the old value takes priority.

**Can I just add upgrade-insecure-requests and move on?**

It works as a stopgap: the browser rewrites the page's http:// requests to https://. But a request fails if the resource is not available over HTTPS, links to other sites are not upgraded, and the wrong URL is still in your code and data. Fix the source, then keep or drop the header.

**Is trusting the proxy safe?**

Only when the proxy is the only way to reach your app and it sets the forwarding headers itself. Django and Express both warn that a client could otherwise send a forged X-Forwarded-Proto and make a plain HTTP request look secure.

**Does Livops need any setting to serve my site over HTTPS?**

No. Every project gets a livops.app address with HTTPS, and a domain you connect gets its certificate automatically once it is live. What you fix is the http:// addresses inside your own code, variables and data.

## Sources

1. [MDN — Mixed content](https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content). Checked 1 December 2026.
2. [Chromium source — mixed_content_checker.cc](https://raw.githubusercontent.com/chromium/chromium/main/third_party/blink/renderer/core/loader/mixed_content_checker.cc). Checked 1 December 2026.
3. [MDN — CSP upgrade-insecure-requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/upgrade-insecure-requests). Checked 1 December 2026.
4. [Vite — Env Variables and Modes](https://vite.dev/guide/env-and-mode). Checked 1 December 2026.
5. [Laravel docs — HTTP Requests, Configuring Trusted Proxies (13.x)](https://laravel.com/docs/13.x/requests). Checked 1 December 2026.
6. [Laravel source — Routing/UrlGenerator.php (13.x)](https://raw.githubusercontent.com/laravel/framework/13.x/src/Illuminate/Routing/UrlGenerator.php). Checked 1 December 2026.
7. [Django docs — Settings (SECURE_PROXY_SSL_HEADER)](https://docs.djangoproject.com/en/6.1/ref/settings/). Checked 1 December 2026.
8. [Django docs — Request and response objects](https://docs.djangoproject.com/en/6.1/ref/request-response/). Checked 1 December 2026.
9. [Express — Express behind proxies](https://expressjs.com/en/guide/behind-proxies.html). Checked 1 December 2026.
10. [Express 5.x API — Request](https://expressjs.com/en/5x/api/request). Checked 1 December 2026.
