Back to commands

Hosting Operations

Read-only

Test Nginx Before Reload

You changed an Nginx config and need to validate syntax before reloading the service.

Command

nginx -t

Before you run this

System impact: Read-only. Low when scoped to the shown target.

When not to use it: Do not treat a syntax pass as proof the upstream app or DNS is correct.

Expected output

A syntax-ok message or a line number for the config error.

System impact

Read-only. Nothing changes. Nginx parses configuration and reports whether reload is safe.

Recovery / rollback: no state is changed.

When to use it

Use this before any Nginx reload or deploy involving server blocks.

When not to use it

Do not treat a syntax pass as proof the upstream app or DNS is correct.

Watch this command run

Command transcript

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

demo@lab:~$

$ nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

$ ls -l /etc/nginx/sites-enabled/

total 0
lrwxrwxrwx 1 root root 38 Jun 26 00:27 example.com -> /etc/nginx/sites-available/example.com

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

/etc/nginx/sites-enabled/example.com:    server_name example.com example.com;
View commands shown

These are the commands shown in the sanitized transcript.

Commands shown

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

next steps

Related commands

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

List Nginx Listen Directives

The site was configured, but the port was not.

grep -RInE '^[[:space:]]*listen[[:space:]]' fixtures/nginx/conf.d fixtures/nginx/sites-enabled
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 Read-only

Show Enabled Nginx Sites

The config existed, but it was not enabled.

ls -l /etc/nginx/sites-enabled/
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.

  • lfcs:operations-deployment
  • lfcs:services-logs
  • 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.