Back to commands

Hosting Operations

Read-only, can be slow

List Nginx Listen Directives

A site is answering on the wrong port, missing HTTPS, or falling through to the wrong server block, and you need to see which Nginx configs claim each listener.

Command

grep -RInE '^[[:space:]]*listen[[:space:]]' fixtures/nginx/conf.d fixtures/nginx/sites-enabled

Before you run this

System impact: Read-only. Can create load on large logs, directories, filesystems, or process tables.

When not to use it: Do not assume a `listen` line proves the service is active. Follow up with `nginx -t` and socket checks when the live state matters.

Expected output

Config filenames and line numbers containing `listen` directives, including any `default_server` flags or address-specific binds.

System impact

Read-only, can be slow. Nothing changes. The command searches config text for `listen` directives; it does not validate that Nginx accepted or bound them.

Scope this to the smallest useful path or service on busy systems.

Recovery / rollback: no state is changed.

When to use it

Use before editing DNS, certificates, or upstream apps when the first question is which server block claims 80 or 443.

When not to use it

Do not assume a `listen` line proves the service is active. Follow up with `nginx -t` and socket checks when the live state matters.

Watch this command run

Command transcript

This sanitized transcript shows the commands and output shape without exposing host details.

demo@lab:~$

$ find sample-files/nginx -type f | sort

sample-files/nginx/conf.d/admin.conf
sample-files/nginx/nginx.conf
sample-files/nginx/sites-enabled/example.conf

$ grep -RInE '^[[:space:]]*listen[[:space:]]' sample-files/nginx/conf.d sample-files/nginx/sites-enabled

sample-files/nginx/conf.d/admin.conf:2:    listen localhost:8080;
sample-files/nginx/sites-enabled/example.conf:2:    listen 80 default_server;
sample-files/nginx/sites-enabled/example.conf:7:    listen 443 ssl;

$ grep -RInE 'default_server|ssl' sample-files/nginx/conf.d sample-files/nginx/sites-enabled

sample-files/nginx/sites-enabled/example.conf:2:    listen 80 default_server;
sample-files/nginx/sites-enabled/example.conf:7:    listen 443 ssl;
View commands shown

These are the commands shown in the sanitized transcript.

Commands shown

  1. find fixtures/nginx -type f | sort
  2. grep -RInE '^[[:space:]]*listen[[:space:]]' fixtures/nginx/conf.d fixtures/nginx/sites-enabled
  3. grep -RInE 'default_server|ssl' fixtures/nginx/conf.d fixtures/nginx/sites-enabled

next steps

Related commands

Hosting Operations Can be slow

Show Nginx Include Lines

The config was valid; it just was not included.

grep -RInE '^[[:space:]]*include[[:space:]]' fixtures/nginx/nginx.conf fixtures/nginx/conf.d fixtures/nginx/sites-enabled
Hosting Operations Can be slow

Map Nginx Roots and Aliases

The URL was right. The filesystem path was not.

grep -RInE '^[[:space:]]*(root|alias)[[:space:]]' fixtures/nginx/conf.d fixtures/nginx/sites-enabled
Hosting Operations Can be slow

Map Nginx Proxy Targets

Nginx was healthy. It was proxying to the wrong place.

grep -RInE '^[[:space:]]*proxy_pass[[:space:]]' fixtures/nginx/conf.d fixtures/nginx/sites-enabled
Hosting Operations Can be slow

Find the Nginx Default Server

The wrong site answered because it was the fallback.

grep -RIn 'default_server' fixtures/nginx/conf.d fixtures/nginx/sites-enabled
Hosting Operations Can be slow

Find Web Server Redirect Rules

The redirect loop was hiding in plain text.

grep -RInE 'return[[:space:]]+30[18]|rewrite[[:space:]]|Redirect[[:space:]]|RewriteRule|RewriteCond' fixtures/nginx fixtures/apache
Study mapping

Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.

  • lpic1:103-gnu-unix-commands
  • lfcs:essential-commands
  • lfcs:operations-deployment
  • lfcs:services-logs
  • linuxplus:automation-scripting
  • linuxplus:provisional
  • risk:read-only

Useful for

  • LPIC-1 style command-line practice
  • LFCS style performance tasks
  • Linux+ style troubleshooting review

Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.