Module 66: Web Server Configuration

Lesson 2 of 5 · 15–25 minutes

Server blocks (virtual hosts)

🏠The everyday picture

One building with several shops, each with its own name board and door. The address on a letter decides which shop it goes to.

📘What it really is

# /etc/nginx/sites-available/crm
server {
    listen 80;
    server_name crm.example.in;

    root /srv/crm/web/dist;
    index index.html;

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

🖱️Try it

Build your React frontend (npm run build) and copy dist/ to /srv/crm/web/dist in your lab. Create the server block above (with a lab name like crm.lab), add that name to your computer's hosts file pointing at the lab's IP, and open http://crm.lab. Reload a deep link like /enquiries/new to check try_files works.

✅Quick check

How does Nginx decide which site to serve when several share one server?

Show the answer

By the domain name in the request (the Host header), matched against each block's server_name.

Why does a React app need try_files $uri $uri/ /index.html?

Show the answer

So any app address that isn't a real file still gets index.html, letting the router handle it.

← PreviousWhat Nginx does
ProLearners Assist