How to Host a React or Next.js App: Developer Hosting Guide
You have built a React or Next.js app that runs perfectly on your laptop. Now you need to put it on the internet, on a domain, over HTTPS, in a way that survives restarts, updates and real traffic. That is where many developers get stuck, not because deployment is hard, but because React and Next.js can be deployed in very different ways, and the right one depends on how your app renders.
This guide shows you how to host a React or Next.js app step by step. You will learn how to choose between a static deployment and a Node.js server, how to deploy a React single-page app, a statically exported Next.js site and a full Next.js server app, how to handle environment variables, routing and HTTPS, and how to fix the errors that trip people up most often.
Key takeaways
Static apps are simple and cheap to host. A React SPA built with Vite, or a Next.js app using static export, is just HTML, CSS and JavaScript files that any web hosting plan can serve.
Server features need Node.js. Server-side rendering, API routes, middleware, Server Actions and ISR in Next.js need a running Node.js process, which means a plan or server that supports Node.js apps.
SPA routing needs a fallback rule. Without one, refreshing a deep link gives a 404.
Environment variables are not secrets on the client. Anything exposed to the browser is public, and many variables are baked in at build time.
Automate it. Build in CI and upload the result, instead of building on a small server.
On SteboHost you can start on web hosting for static front-ends and move to Developer Hosting or a VPS when your app needs a Node.js server.
Step Zero: Decide How Your App Renders
Before touching a server, work out which of these three situations you are in. It determines everything that follows.
Your app | What the build produces | What the server must do | Hosting needed |
|---|---|---|---|
React SPA (for example Vite) | A folder of static files (dist) | Serve files and fall back to index.html | Any web hosting plan |
Next.js with static export | A folder of static files (out) | Serve files | Any web hosting plan |
Next.js with server features | A Node.js application | Run a Node.js process behind a web server | Node.js-capable plan or VPS |
Choose static export when your site is mostly content (marketing pages, documentation, a portfolio, a blog) and does not need per-request server logic. It is the fastest, cheapest and most reliable option.
Choose a Node.js server when you need server-side rendering on every request, authentication with server sessions, API routes or route handlers that read requests, middleware, Server Actions, incremental static regeneration, or the built-in image optimisation.
What You Need Before You Deploy
A project that builds cleanly on your own machine with
npm run buildYour project in Git, with a lock file (package-lock.json, yarn.lock or pnpm-lock.yaml) committed
The Node.js version your framework requires. Check your Next.js or build tool's documentation, and use the same major version locally, in CI and on the server
A domain pointed at your hosting. If you do not have one, register your domain, and manage records through managed DNS
Access to your hosting account over SFTP or SSH, plus the details of your plan from the plan limits page
A list of environment variables your app needs, split into public (safe for the browser) and private (server only)
Path 1: Deploy a React Single-Page App
This applies to React apps built with Vite or a similar bundler. (Create React App has been deprecated by the React team, and new projects typically start with Vite or a framework such as Next.js.)
Step 1: Set the base path and build
If your app lives at the root of a domain, the defaults are fine. If it lives in a subfolder such as example.com/app, set the base path in your build tool (for Vite, the base option in vite.config) so asset links resolve correctly. Then build:
npm ci
npm run buildThe output is in the dist folder (build for some setups). Open it and confirm it contains index.html and an assets folder with hashed file names.
Step 2: Upload the build
Upload the contents of dist, not the folder itself, into your site's web root (usually public_html, or the folder for your domain). You can use the control panel's File Manager, an SFTP client, or rsync over SSH if your plan allows it:
rsync -avz --dry-run -e ssh ./dist/ username@yourdomain.com:~/public_html/Remove --dry-run when the preview looks right. Be careful with --delete, which removes server files that are not in your build.
Step 3: Add the SPA routing fallback
A single-page app handles its routes in the browser. If someone opens yourdomain.com/dashboard directly or refreshes the page, the server looks for a file called dashboard, finds nothing and returns 404. Fix it by sending unknown paths to index.html. On Apache-compatible servers, including LiteSpeed, create or edit .htaccess in the web root:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>This serves real files and folders as they are, and sends everything else to your app.
Step 4: Force HTTPS and set caching
Turn on HTTPS and redirect HTTP to HTTPS. SteboHost issues free SSL on every domain, and our guide on setting up free SSL and forcing HTTPS covers the redirect rules in detail.
For caching, bundlers such as Vite put a content hash in file names (for example index-3f2a1b.js). That makes it safe to cache those files for a year, while index.html should not be cached for long so users get new releases:
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|woff2)$">
Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>
<Files "index.html">
Header set Cache-Control "no-cache"
</Files>
</IfModule>Only use long-lived caching for files whose names change when their content changes.
Step 5: Test
Open the site, navigate to a deep link, refresh it, and check the browser console for errors. Confirm that API calls point to the right production URL and that your API allows requests from your domain (CORS).
Path 2: Deploy Next.js as a Static Site
Next.js can export a fully static site, which makes it deployable to ordinary web hosting.
Step 1: Enable static export
In your Next.js configuration file, set the output mode:
// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
trailingSlash: true,
images: { unoptimized: true },
};
module.exports = nextConfig;Three settings matter here. output: 'export' produces a static build in the out folder. trailingSlash: true creates a folder with an index.html for each route, so URLs like /about/ work on a plain file server without extra rewrite rules. images: { unoptimized: true } is needed because the default image optimiser requires a running server (you can also use an external image loader).
Step 2: Know the limits
A static export cannot use features that need a server at request time. Depending on your Next.js version, this includes middleware, redirects, rewrites and custom headers defined in the config, incremental static regeneration, Server Actions, draft mode, route handlers that read the request, and dynamic routes that are not pre-generated at build time. Check the "Static Exports" page of the Next.js documentation for your version. If your app depends on any of these, use Path 3.
Step 3: Build and upload
npm ci
npm run buildUpload the contents of the out folder to your web root, exactly as in Path 1. Next.js also produces a 404.html, which you can wire up so missing pages show your own error page:
ErrorDocument 404 /404.htmlAdd that line to .htaccess. Do not add the SPA fallback rule from Path 1 here, because a statically exported site already has a real file for each page.
Path 3: Deploy Next.js With a Node.js Server
If you use server-side rendering, API routes, middleware, Server Actions or ISR, your app needs a long-running Node.js process. You have two sensible places to run it: a plan that supports Node.js applications, such as Developer Hosting, where you should check the plan page for the supported Node.js versions and how apps are started, or a VPS where you control the whole server. The framework steps below are the same in both cases. The VPS steps that follow use Ubuntu or Debian commands.
Step 1: Prepare the app
For servers with limited disk space and memory, the standalone output creates a minimal production bundle. Add this to your Next.js configuration:
const nextConfig = {
output: 'standalone',
};Make sure your Node.js version on the server meets your Next.js release's requirement, and that private environment variables are ready (see the environment section below).
Step 2: Build
Building can use a lot of memory. If your server is small, build on your computer or in CI and upload the result instead of building on the server.
npm ci
npm run buildWith standalone output, copy the static assets next to the generated server before you run it:
cp -r public .next/standalone/public
cp -r .next/static .next/standalone/.next/staticStep 3: Run it
With the standard output, start the production server on a port of your choice:
PORT=3000 npm run startWith the standalone output, run the generated server file. Binding to 127.0.0.1 keeps it reachable only through your web server:
PORT=3000 HOSTNAME=127.0.0.1 node .next/standalone/server.jsStep 4: Keep it running
A process started in a terminal stops when you close the session or the server restarts. Use a process manager. PM2 is a common choice:
npm install -g pm2
PORT=3000 HOSTNAME=127.0.0.1 pm2 start .next/standalone/server.js --name myapp
pm2 save
pm2 startupThe last command prints a line to run with administrator rights, which registers PM2 to start on boot. You can also use a systemd service or Docker if you prefer. On shared environments, follow your host's own Node.js application tool, since long-running processes are managed differently there.
Step 5: Put a web server in front (VPS)
Do not expose Node.js directly on port 80 or 443. Put Nginx in front as a reverse proxy to handle HTTPS, compression and static files. Create a site configuration (on Ubuntu, in /etc/nginx/sites-available):
server {
listen 80;
server_name example.com www.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Enable the site, test the configuration and reload Nginx:
sudo ln -s /etc/nginx/sites-available/example /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginxStep 6: Add HTTPS and a firewall (VPS)
Issue a free Let's Encrypt certificate with Certbot, and allow only the traffic you need:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enableAllow SSH before you enable the firewall, or you can lock yourself out. Use a non-root user for running the app, keep the system updated, and protect SSH with keys.
Step 7: Deploy updates
Pull or upload the new build, install dependencies, rebuild, then reload the process so users see little to no downtime:
git pull origin main
npm ci
npm run build
pm2 reload myappKeep the previous build (or a Git tag) so you can roll back quickly if the release has a problem.
Environment Variables and Secrets
Environment variables are one of the biggest sources of confusion in React and Next.js deployments.
Browser-exposed variables are public. In Vite, variables prefixed with VITE_ are included in the client bundle. In Next.js, variables prefixed with NEXT_PUBLIC_ are. Anyone can read them in the browser, so never put secret keys or passwords in them.
Many are baked in at build time. Changing a public variable on the server does nothing until you rebuild. If a value is undefined in production, check whether it was available when the build ran.
Server-only variables stay on the server. In Next.js, variables without the public prefix are available only to server code. Store them in the environment of the process or in a file that is not committed to Git.
Never commit .env files with real secrets. Add them to .gitignore and rotate any key that was ever committed.
Automate Your Deployments
Manual uploads work, but they are easy to get wrong. A simple CI pipeline does the same thing every time:
Trigger on a push to your main branch.
Install dependencies from the lock file and run your tests and linting.
Build the app with production environment variables stored as encrypted secrets in your CI provider.
Upload the build to your host with rsync or SFTP, or SSH in and reload your process.
Run a quick check against the live URL.
Building in CI also solves the problem of small servers running out of memory during npm run build.
Performance and SEO Tips
Cache hashed assets for a long time and keep index.html fresh, as shown above.
Compress and optimise images. Use modern formats such as WebP or AVIF and sensible dimensions. With static export, pre-optimise images or use an external image service.
Split your code. Lazy-load heavy routes and components so first load stays small.
Mind your SEO. A client-rendered React SPA depends on search engines running your JavaScript to see content. For content you want to rank, prefer static generation or server-side rendering in Next.js, set unique titles and descriptions for each page, and publish a sitemap.xml and robots.txt.
Serve everything over HTTPS, which also allows browsers to use HTTP/2 and HTTP/3.
Measure. Run PageSpeed Insights before and after changes and watch your Core Web Vitals.
Troubleshooting Common Problems
404 when you refresh a page (React SPA). The SPA fallback rule is missing or the .htaccess file is in the wrong folder. Add the rewrite rule from Path 1.
Blank page and missing JavaScript files. The base path is wrong, or you uploaded the dist folder itself instead of its contents. Check the Network tab for 404s on your assets.
Images broken on a static Next.js export. You did not set
images: { unoptimized: true }or an external loader.502 Bad Gateway behind Nginx. Your Node.js app is not running, crashed, or is listening on a different port than the proxy expects. Check
pm2 logsand the port.EADDRINUSE (port already in use). Another process holds the port. Stop it or pick a different port.
The build fails with an out-of-memory error. Build in CI or locally, or increase the server's memory.
Environment variable is undefined. Check the prefix, and remember that public variables are fixed at build time.
Wrong Node.js version. Errors about syntax or missing modules often mean the server's Node.js is older than the version your project needs.
CORS errors calling your API. Allow your production domain on the API server.
Mixed content warnings. A request or asset uses http:// on an HTTPS page. Update the URL.
Security Checklist for Production
Keep secrets out of the client bundle and out of Git.
Run
npm auditand keep dependencies and Node.js up to date.Serve the app over HTTPS only.
Run the Node.js process as a non-root user.
Add a firewall and web application protection. See website security.
Back up your data and test restores. See backup and disaster recovery.
Monitor uptime and errors. See monitoring.
Why Host Your React or Next.js App With SteboHost
SteboHost gives you a clear path from a simple static front-end to a full production server:
Start small on web hosting. Static React and Next.js builds run on SteboHost web hosting with LiteSpeed and NVMe storage, cPanel, free SSL and daily backups with 7-day retention and one-click restore.
Built with developers and agencies in mind. Manage multiple client sites with predictable pricing, free migration and a support team that understands technical questions. See Developer Hosting for what is included in your plan.
Scale to a VPS when you need to. VPS and cloud hosting gives you dedicated CPU and RAM, full root access, Ubuntu, Debian and AlmaLinux images, and snapshot backups for Node.js servers, background workers and anything else shared hosting cannot run. Current upgrade terms are listed on the product pages.
Security included. WAF and Imunify360 malware scanning on every plan, plus 24/7 infrastructure monitoring and a 99.9% uptime SLA.
Free migration on annual plans. Move an existing app and its databases without doing it all yourself.
Local support and local billing. Support on +254 703 610 464 and payments in KES by M-Pesa, card or bank transfer, with renewal prices shown before you buy.
Plan limits, including how many websites each plan covers, are published on each plan page. Compare plans and pricing or browse the knowledge base for more developer guides.
Conclusion
Hosting a React or Next.js app comes down to one question: does it need a server at request time? If not, build static files, upload them, add a routing fallback, turn on HTTPS and cache sensibly. If it does, run a Node.js process behind a web server, keep it alive with a process manager, and automate your deployments. Get those foundations right and you can ship updates confidently without worrying about how they reach the internet.
Ready to deploy your next project? Explore SteboHost Developer Hosting or VPS and cloud hosting, or contact SteboHost support on +254 703 610 464 or support@stebohost.com to find the right plan for your stack.
Frequently Asked Questions
Can I host a React app on shared hosting?
Yes. A React app built with Vite or a similar tool compiles to static HTML, CSS and JavaScript, which any web hosting plan can serve. You just need to upload the build output and add a rewrite rule so deep links fall back to index.html.
Can I host Next.js on shared hosting?
Only in static export mode. A statically exported Next.js site is plain files and works on ordinary hosting. If your app uses server-side rendering, API routes, middleware, Server Actions or ISR, it needs a Node.js server, so use a plan that supports Node.js applications or a VPS.
Do I need Node.js on the server to host a React app?
No, not for a static React build. Node.js is needed on your development machine or in CI to build the app, but the finished site is just static files. You only need Node.js on the server if you run a server-rendered framework such as Next.js with server features.
Why does my React app show a 404 when I refresh the page?
Because the server is looking for a file that matches the URL, and your single-page app only has index.html. Add a fallback rule that sends unknown paths to index.html, as shown in Path 1.
Do I need a VPS to run Next.js?
Not always. Static export works on regular web hosting, and some plans support Node.js applications directly. A VPS is the right choice when you need full control, such as a custom Node.js version, background workers, a database on the same server, Docker or a reverse proxy configuration of your own.
How do I keep my Next.js app running after I close the terminal?
Use a process manager such as PM2, a systemd service or Docker, so the process restarts automatically after crashes and reboots. On a managed Node.js hosting plan, use the platform's own tool for running applications.
How can I deploy updates without downtime?
Build the new version first, then swap or reload the running process, for example with pm2 reload. For static sites, upload the new build and keep index.html uncached so users receive the new version. Kee previous build around so you can roll back quickly.
Written by Denis Makokha
SteboHost engineering and operations team. We write practical guides on hosting, domains, email and security for African businesses — based on what we see in the field, not marketing copy.
Ready to get started?
Browse our hosting plans or contact our team for help choosing the right one.