ThisCalculator

Everyday

Web Server Showing Build Folder? Fix It Now

Updated · Standard formula, shown below

If your web server is displaying your build folder (like dist/ or build/) as a directory listing, it means the server is not configured to serve the contents of that folder as the root of your site. The fix is to point your server’s document root to the build folder, or to configure a rewrite rule that routes all requests to its index.html file.

Why This Happens

Modern front-end frameworks (React, Vue, Angular, Svelte) compile your source code into static files in a build folder. When you upload these files to a server, the server needs to know which directory to serve as the website’s root. If the server is set to serve the parent directory (the one containing the build folder), it will show a directory listing instead of your app. This is especially common when using shared hosting, a basic Nginx or Apache setup, or a static file server that defaults to the current directory.

How the Server Decides What to Show

Web servers have a concept of a “document root” — the folder that maps to the site’s root URL (/). When you visit example.com, the server looks for files inside that root. If the root is set to the folder that contains build/, the server will list that folder’s contents (including the build/ directory itself) rather than the files inside it. If the root is set to the build/ folder itself, the server will serve index.html and other assets correctly.

Fixing It on Common Servers

Here are the exact steps for the most common server setups:

Apache (with .htaccess)

  1. Create or edit the .htaccess file in the folder where you uploaded your build folder.
  2. Add the following rewrite rule to serve the build folder as the root:
RewriteEngine On
RewriteRule ^$ build/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ build/$1 [L]

This tells Apache to serve files from the build/ subdirectory for all requests, unless an existing file or directory is requested directly.

Nginx

  1. Edit your site’s Nginx configuration file (usually in /etc/nginx/sites-available/).
  2. Change the root directive to point to the build folder:
server {
    listen 80;
    server_name example.com;
    root /var/www/example.com/build;
    index index.html;
    location / {
        try_files $uri $uri/ /index.html;
    }
}

The try_files line ensures that client-side routes (like /about) fall back to index.html for your JavaScript app to handle.

Static Hosting (Netlify, Vercel, GitHub Pages)

  • For Netlify and Vercel, set the “publish directory” or “output directory” to the name of your build folder (e.g., build or dist).
  • For GitHub Pages, you can either push the build folder contents to the gh-pages branch, or use a GitHub Action to deploy the build folder automatically.

What If You Don’t Want to Change the Document Root?

If you cannot change the document root (for example, on shared hosting where you only have access to public_html), you have two options:

  • Move the contents of the build folder up one level, so index.html and assets are directly in the public root.
  • Use a rewrite rule as shown above for Apache to redirect all requests to the build subfolder.

The first option is simpler and more reliable, because it avoids any rewrite complexity and works with any server that supports serving static files.

Common Mistakes and Pitfalls

  • Forgetting to include the trailing slash in the root directive (Nginx) — it should be /path/to/build, not /path/to/build/ (though both may work, the correct form is without the trailing slash).
  • Not enabling mod_rewrite in Apache — if the .htaccess rules don’t work, check that AllowOverride All is set for the directory in the main Apache config.
  • Using absolute paths incorrectly in the Nginx root — the path must be the full filesystem path, not a URL.
  • Forgetting to clear the browser cache — after changing the server config, you may still see the old directory listing due to caching. Do a hard refresh (Ctrl+F5) or test in an incognito window.

When the Directory Listing Is Intentional

Sometimes you might actually want the server to show a directory listing — for example, if you’re hosting a file download area. In that case, you can enable autoindex in Nginx (autoindex on;) or Options +Indexes in Apache. But for a web application, directory listings are almost never what you want, because they expose your file structure and break the user experience.

Frequently Asked Questions

Why do I see the build folder instead of my website?

Your server’s document root is set to a directory that contains the build folder, rather than the build folder itself. The server is simply listing the files in that directory, which includes the build folder.

Can I just rename the build folder to public_html?

Yes, if you have access to rename folders on your server. This effectively makes the build folder the document root. However, you’ll need to update any absolute paths in your code if you used /build/ in URLs.

What is the difference between document root and root in Nginx?

They are the same concept. The root directive in Nginx sets the document root for the server block. Changing it to point to the build folder is the standard fix.

Why does my SPA show a 404 on refresh when I use the build folder as root?

This happens because the server doesn’t know how to handle client-side routes. You need to add a fallback rule (like try_files $uri $uri/ /index.html; in Nginx) so that all requests go to index.html.

Is it safe to expose the build folder to the public?

Yes, the build folder contains static assets that are meant to be public. However, make sure your build process does not include sensitive files like .env or source maps that could reveal code. Configure your build tool to exclude them.

What if I’m using a Node.js server like Express?

In Express, you can serve the build folder with app.use(express.static('build')). This will make the contents of the build folder available at the root path.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.