↑ ↓ select, Enter open, Esc close

Show all nginx server_name entries with their config file

root@server
nginx -T 2>/dev/null | grep -E "^# configuration file|server_name "

nginx -T tests the configuration and then prints it in full, each file introduced by a comment line with its file name. The filter keeps only those file lines and the server_name directives. This quickly shows which server block handles a domain and whether it appears twice.

Note: Without the grep, nginx -T > /root/nginx-dump.txt gives a complete backup of the effective configuration to read through.

Also searched as

  • which domains does nginx serve
  • find file containing nginx server block
  • dump full nginx configuration
  • nginx serving wrong site

Related one-liners

All in nginx

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.