000%
TUNING INTUITION TO VELOCITY
← All insights

How to host a Flutter web app on an Ubuntu server with nginx

3 min read · September 2024

This guide takes a Flutter project to a live website on an Ubuntu server, served by nginx. Every command comes from the official Flutter, nginx and Ubuntu documentation, which we last checked in November 2026. Flutter and Ubuntu change, so follow the linked pages if anything differs on your machine.

What you need

  • An Ubuntu server you can reach over the command line, and an account on it that can use sudo to install packages.
  • A Flutter project in a git repository.
  • A domain name or the server's address to open the site.

1. Install the packages Flutter needs

Flutter's documentation lists a few packages for Debian-based systems such as Ubuntu. Install them with these two commands:

sudo apt-get update -y && sudo apt-get upgrade -y
sudo apt-get install -y curl git unzip xz-utils zip libglu1-mesa

2. Install the Flutter SDK

Download the latest stable Linux bundle from the Flutter SDK archive, then extract it into a folder in your own user directory. Flutter's documentation suggests ~/develop/ and warns against a location that needs elevated privileges, so do not use sudo for this step. The version number in the file name changes with each release; use the name of the file you downloaded:

mkdir -p ~/develop
tar -xf ~/Downloads/flutter_linux_<version>-stable.tar.xz -C ~/develop/

Then add Flutter to your PATH so the flutter command works in every terminal, and check the setup:

echo 'export PATH="$HOME/develop/flutter/bin:$PATH"' >> ~/.bash_profile
flutter doctor

Open a new terminal session first so the change applies. You only need a checkmark for Flutter and for the platform you build for, which here is the web.

3. Get your project and build the web app

Clone your repository, fetch the project's packages and build:

git clone <your-repository-url>
cd <your-project-folder>
flutter pub get
flutter build web

The build places the finished site, including its assets, in the build/web folder of your project.

4. Install nginx

Ubuntu's documentation installs nginx with one command, and it starts the server for you:

sudo apt update && sudo apt install nginx
sudo systemctl status nginx

5. Serve the build with nginx

Copy the contents of build/web to the folder nginx will serve, then point nginx at it. nginx's configuration file is named nginx.conf and, by default, sits in /usr/local/nginx/conf, /etc/nginx or /usr/local/etc/nginx (on a standard Ubuntu install, look in /etc/nginx). Add a server block like this one, with your own domain and folder:

server {
    listen 80;
    server_name example.com;
    root /var/www/myapp;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }
}

The try_files line sends any address that is not a real file to index.html. You only need it if your app uses path URLs such as example.com/page. Flutter's documentation says a path-based app needs the web server to rewrite requests to index.html; the default hash URLs do not.

6. Test and reload

nginx can check the configuration before you apply it, and reload it without stopping the server:

sudo nginx -t
sudo nginx -s reload

Then open your domain or the server's address in a browser.

Before you go live

  • Keep source maps out of public hosting. Flutter's documentation warns that publicly served .map files expose unminified symbol names, class structure and local file paths; exclude *.map files from the folder nginx serves.
  • Do not run the SDK, your project or the web server as the root user.
  • Serve the site over HTTPS and review your server's firewall before sending real visitors.

Sources