wordpress 2026-12-02 ⏱ 4 min read

Enable HTTPS on React Websites

Enable HTTPS on React Websites

React is a front-end library. It runs in the browser and has no say over how files reach the user, so HTTPS is a hosting question, not a React setting. The answer changes depending on whether you are developing locally or serving a production build.

HTTPS on React websites: local development

Most of the time you can develop on plain http://localhost, since browsers treat it as a secure context. You need local HTTPS only when testing things like secure cookies, third-party callbacks, or a service that refuses http:// origins.

With Create React App style tooling, set environment variables before starting the dev server. With Vite, enable the server option and supply a certificate.

# Create React App (macOS or Linux)
HTTPS=true npm start

# Vite: vite.config.js
server: { https: { key: fs.readFileSync("key.pem"),
  cert: fs.readFileSync("cert.pem") } }

Generate trusted local files with mkcert. Browsers will warn about any self-signed certificate you do not install into your trust store. Tool options change between versions, so check the current docs for your build tool.

HTTPS on React websites: production

npm run build produces static files. Whoever serves those files must provide the certificate. The three common cases:

HostingHow HTTPS worksYour job
Static host or CDNThe provider issues a certificate for your custom domainAdd the domain, set DNS, wait for issuance
Shared hosting or cPanelA control panel tool installs a free certificateTurn on AutoSSL or use the SSL tool, then add a redirect
Your own VPSYou run Nginx, Apache or CaddyInstall a free certificate and configure the server

Provider behavior and limits vary, so confirm details in the current docs. If your host blocks custom certificates altogether, see free SSL versus hosting provider SSL.

Self-managed server with Nginx

Copy the build folder to the server and point Nginx at it. React Router apps need a fallback to index.html, or deep links return 404.

server {
    listen 443 ssl;
    server_name example.com;
    root /var/www/app/build;
    ssl_certificate /etc/ssl/example/fullchain.pem;
    ssl_certificate_key /etc/ssl/example/privkey.pem;
    location / { try_files $uri /index.html; }
}
server {
    listen 80;
    server_name example.com;
    return 301 https://example.com$request_uri;
}

Use the full chain file, not just the leaf certificate. Missing intermediates work in some browsers and fail in others and in API clients. You can confirm that your key and certificate belong together with the key pair matcher guide.

Stop mixed content in your React code

A page served over HTTPS that loads a script, image or API from http:// will be blocked or flagged. Search your source for hardcoded http:// URLs and move API base URLs into environment variables, so staging and production each use https://. Prefer protocol-relative thinking: if you control the endpoint, always use HTTPS.

  • Check .env files for REACT_APP_ or VITE_ API URLs that start with http://.
  • Check CSS url() values and public/index.html for old links.
  • Watch the browser console for "Mixed Content" messages.

Our WordPress mixed content guide explains the browser rules in more depth, and they apply to React too.

After HTTPS works

  1. Redirect all HTTP traffic to HTTPS at the server or CDN.
  2. Add an HSTS header once you are sure every subdomain supports HTTPS. See the security headers audit guide.
  3. Set up automatic renewal and test it. Free certificates are short-lived by design.
  4. Update your sitemap, canonical tags and any OAuth redirect URLs to https://.

Free certificates are fine for most React sites. If you are weighing options, read the free certificate comparison.

Troubleshooting

  • Blank page after deploy: the build is probably requesting assets from http:// or a wrong base path. Check the Network tab.
  • Redirect loop behind a CDN: the CDN may reach your origin over HTTP while the origin redirects to HTTPS. Use an end-to-end encrypted mode at the CDN.
  • API calls blocked: the browser refuses http:// API calls from an HTTPS page. Move the API to HTTPS too.
  • Certificate warning only on www: you issued the certificate for the apex name only. Reissue with both names.

If you proxy through Cloudflare, the choice between origin certificates and a public CA matters. We compare them in Cloudflare Origin CA versus Let's Encrypt.

Related reading: free SSL for Next.js, mixed content warnings, free SSL on nginx and free SSL on Vercel and Netlify.

Frequently Asked Questions

Does React need its own certificate?

No. React runs in the browser, and the certificate belongs to whatever serves the build: a static host, a CDN or Nginx.

How do I use HTTPS in local development?

Set HTTPS=true in a Create React App project, or point the dev server at a local certificate. Plain http://localhost already counts as a secure context for most browser APIs.

Why does my build still load http assets?

A hardcoded http URL in the code or in an environment variable. Search the build output for http:// and fix it at the source.

🔒 Test Your Website SSL Certificate Now
Run Free SSL Check →

✅ Post-Installation Verification & SEO Checklist

After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:

  • Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
  • Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
  • Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
  • Confirm both root and www versions resolve cleanly to one canonical HTTPS URL.
  • Verify your HTTPS property and sitemap.xml inside Google Search Console and Bing Webmaster Tools.
Technically Reviewed by TryFreeSSL Security Team
Last updated: 2026-12-05
About Us →

Free SSL Certificates, Live SSL Checker & CSR Generator

Issue trusted Let's Encrypt SSL certificates in 60 seconds with zero server setup.

Related Articles

🤖 TryFreeSSL AI Assistant