Back to lessons

Hosting Operations

Find Which Nginx Config Owns a Domain

You need to find which Nginx config contains a domain's `server_name`.

Command

grep -R "server_name" /etc/nginx/sites-enabled/

What changed

Nothing changes. The command searches enabled server names.

Danger

safe

When to use it

Use this when a domain routes to the wrong site.

When not to use it

Do not assume the first match controls HTTPS if separate SSL configs exist.

Undo or recovery

No state is changed.

Expected output

Config paths with matching `server_name` lines.

demo script

Disposable terminal steps

  1. grep -R "server_name" /etc/nginx/sites-enabled/
  2. grep -R "root" /etc/nginx/sites-enabled/
  3. nginx -t

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ grep -R "server_name" /etc/nginx/sites-enabled/
/etc/nginx/sites-enabled/example.com:    server_name example.com www.example.com;
::exit-code::0
$ grep -R "root" /etc/nginx/sites-enabled/
/etc/nginx/sites-enabled/example.com:    root /srv/www/example.com/current;
::exit-code::0
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
::exit-code::0

YouTube Short

Find the Nginx config for a domain.

When the wrong site answers, search the enabled server names before editing random files.

LinkedIn hook

The wrong server block was answering the domain.

Question: What do you check first when Nginx serves the wrong site?

experiments

A/B tests to run

Metric: linkedin_comment_rate

A: Find which Nginx config owns a domain.

B: The wrong server block was answering.