Hosting Operations
Read-onlyTest 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.
$ 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
nginx -tls -l /etc/nginx/sites-enabled/grep -R "server_name" /etc/nginx/sites-enabled/
next steps
Related commands
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
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
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
Find Which Nginx Config Owns a Domain
The wrong server block was answering the domain.
grep -R "server_name" /etc/nginx/sites-enabled/
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.
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.