# How I build a basic nginx config without starting from an empty file

A beginner-friendly guide to nginx server blocks for static sites, SPAs, PHP, and reverse proxy setups.

- Date: 2026-09-27
- URL: https://ilham.dev/posts/how-to-build-a-basic-nginx-config/
- Markdown: https://ilham.dev/posts/how-to-build-a-basic-nginx-config/index.md
- Tags: nginx, devops, web-server, tools
- Reading time: 2 min


An nginx config is easier to write when I start from the kind of site I am serving: static files, SPA, PHP, or reverse proxy.

The [nginx Config Generator](/tools/nginx-config-generator/) tool helps me inspect the input and output without writing a one-off script first.

## The simple idea

An nginx config is easier to write when I start from the kind of site I am serving: static files, SPA, PHP, or reverse proxy.

I use it to answer one focused question at a time, then I review the result before using it anywhere important.

## Step 1: Choose the site type

Choose the site type.

## Step 2: Enter the domain name

Enter the domain name.

## Step 3: Set the document root or upstream app

Set the document root or upstream app.

## Step 4: Choose index and fallback behaviour

Choose index and fallback behaviour.

## Step 5: Add TLS or redirect assumptions carefully

Add TLS or redirect assumptions carefully.

## Step 6: Generate the config and read it before using it

Generate the config and read it before using it.

## Step 7: Run `nginx -t` before reloading nginx

Run `nginx -t` before reloading nginx.

## My checklist

Before I trust the result, I check:

- Choose the site type.
- Enter the domain name.
- Set the document root or upstream app.
- Choose index and fallback behaviour.
- Add TLS or redirect assumptions carefully.
- Generate the config and read it before using it.
- Run `nginx -t` before reloading nginx.

The tool makes the mechanical part faster. The decision still belongs to me: is this result correct, safe, and appropriate for the real task?
