Back to lessons

Hosting Operations

Find the Nginx Default Server

You need to find which Nginx server block is marked as the default.

Command

grep -RIn 'default_server' fixtures/nginx/conf.d fixtures/nginx/sites-enabled

What changed

Nothing changes. The command searches for default_server flags.

Danger

safe

When to use it

Use when requests without a matching host header land on an unexpected site.

When not to use it

Do not treat the default server as the cause when the Host header or DNS is still unknown.

Undo or recovery

No undo needed because this command is read-only.

Expected output

Config paths and line numbers where default_server appears.

demo script

Disposable terminal steps

  1. grep -RIn 'default_server' fixtures/nginx/conf.d fixtures/nginx/sites-enabled
  2. grep -RInE '^[[:space:]]*server_name[[:space:]]' fixtures/nginx/conf.d fixtures/nginx/sites-enabled

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ grep -RIn 'default_server' fixtures/nginx/conf.d fixtures/nginx/sites-enabled
fixtures/nginx/sites-enabled/example.conf:2:    listen 80 default_server;
::exit-code::0
$ grep -RInE '^[[:space:]]*server_name[[:space:]]' fixtures/nginx/conf.d fixtures/nginx/sites-enabled
fixtures/nginx/conf.d/admin.conf:3:    server_name admin.internal;
fixtures/nginx/sites-enabled/example.conf:3:    server_name example.com www.example.com;
fixtures/nginx/sites-enabled/example.conf:8:    server_name example.com www.example.com;
::exit-code::0

YouTube Short

Find the fallback server.

If Nginx serves the wrong site, look for default_server. That line decides where unmatched requests go.

LinkedIn hook

The wrong site answered because it was the fallback.

Question: Have you debugged the wrong Nginx site because the fallback answered?

experiments

A/B tests to run

Metric: comment_rate

A: Fallback answered.

B: Find default_server fast.