
Many teams deploy Flutter web apps to managed static hosts, but there are plenty of reasons to use your own server instead. You may already have infrastructure in place, need to meet compliance requirements, want to host the app alongside a backend API, or simply prefer predictable costs and full control. Because a Flutter web build is a collection of static files, serving it from a Linux server is straightforward once you configure the web server correctly. This guide covers the entire process, from building the app to securing and automating your deployment.
How AAMAX.CO Helps Host Flutter Apps on Custom Servers
Configuring servers for modern web apps takes skill, and AAMAX.CO provides it. They are a full service digital marketing company offering web development, digital marketing, and SEO services worldwide. Their team can provision secure servers, configure Nginx or Apache for Flutter builds, set up SSL certificates, and automate deployment pipelines. They also integrate the app with backend services and databases hosted on the same infrastructure. Businesses that hire them benefit from a stable, optimized hosting environment managed by experienced professionals.
Build the Flutter Web App
On your development machine or CI system, run flutter build web --release. If the app will live in a subdirectory, such as example.com/app/, add --base-href /app/ so asset paths resolve correctly. The output in build/web contains index.html, compiled JavaScript or WebAssembly files, assets, fonts, icons, the manifest, and service worker files. This folder is everything your server needs.
Prepare the Server
Provision a Linux server, such as Ubuntu LTS, from your preferred provider. Create a non-root user, configure SSH key authentication, enable a firewall that allows SSH, HTTP, and HTTPS, and apply system updates. Create a directory for the app, such as /var/www/flutter-app, and assign ownership to the deployment user.
Upload the Build Files
Transfer the build/web contents to the server directory. You can use rsync for efficient incremental uploads, SCP for simple copies, or SFTP clients for a graphical approach. Rsync with the delete option ensures that old files are removed, preventing stale assets from lingering. For a more robust workflow, upload each release into a timestamped folder and switch a symlink to the latest version, enabling instant rollbacks.
Configure Nginx
Nginx is a popular choice for serving static apps efficiently. Install it and create a server block for your domain. Key settings include:
- A root directive pointing to your Flutter build directory.
- An index directive set to index.html.
- A try_files rule that falls back to /index.html for unknown routes, enabling deep links with path-based URLs.
- Gzip or Brotli compression for JavaScript, CSS, JSON, and WebAssembly files.
- A correct MIME type for .wasm files so browsers can stream-compile them.
Test the configuration with nginx -t and reload the service to apply changes.
Configure Apache as an Alternative
If your server runs Apache, enable mod_rewrite and create an .htaccess file or virtual host configuration that rewrites requests for non-existent files to index.html. Enable mod_deflate for compression and mod_headers for caching rules. Apache works well when you need to host the Flutter app alongside existing PHP sites or legacy applications.
Enable HTTPS
Point your domain's DNS A record to the server's IP address. Install Certbot and run it with the Nginx or Apache plugin to obtain a free Let's Encrypt certificate. Certbot updates the configuration and schedules automatic renewal. Redirect all HTTP traffic to HTTPS, since service workers and many browser APIs only work on secure origins.
Set Smart Caching Rules
Caching dramatically improves repeat-visit performance. Assets such as fonts, images, and hashed JavaScript files can be cached for long periods. However, index.html, flutter_bootstrap.js, flutter_service_worker.js, and version.json should be served with no-cache headers so browsers check for updates. Getting this balance right prevents users from being stuck on outdated versions after a release.
Serve the App Alongside an API
A major benefit of self-hosting is the ability to run your backend on the same server or network. Configure Nginx to serve the Flutter app at the root path and proxy requests under /api/ to your backend service running on a local port. This setup avoids cross-origin issues, simplifies authentication cookies, and keeps latency low. Integrated frontend and backend hosting is a common pattern in professional web application development.
Automate Deployments
Use GitHub Actions, GitLab CI, or another pipeline to build the Flutter app and deploy it via rsync over SSH. Store the private SSH key as a secret and restrict the deployment user's permissions. After uploading, the script can switch symlinks and reload Nginx if necessary. Automation ensures consistent releases and saves time.
Monitor and Maintain
Keep the operating system and web server updated. Monitor uptime, disk space, and SSL certificate expiration. Review access and error logs to detect issues or suspicious activity. Periodically test the site on multiple browsers and devices to catch regressions.
Conclusion
Deploying a Flutter web app on your own server involves building a release, uploading files, configuring Nginx or Apache with SPA rewrites, enabling HTTPS, setting cache headers, and automating releases. With this setup, you gain full control and can host your Flutter frontend alongside your backend services for a seamless, high-performance experience.
