0
0
NginxHow-ToBeginner · 3 min read

How to Check Nginx Status: Simple Commands and Examples

To check the status of nginx, use the command systemctl status nginx on systems with systemd. Alternatively, you can test the configuration with nginx -t to ensure it is valid and the service can start properly.
📐

Syntax

Use the following commands to check the status of the Nginx service:

  • systemctl status nginx: Shows if Nginx is running, stopped, or failed.
  • nginx -t: Tests the Nginx configuration for errors without starting the service.
bash
systemctl status nginx

nginx -t
💻

Example

This example shows how to check if Nginx is active and verify its configuration.

bash
sudo systemctl status nginx

sudo nginx -t
Output
● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2024-06-11 10:00:00 UTC; 5min ago Docs: man:nginx(8) Main PID: 1234 (nginx) Tasks: 3 (limit: 4915) Memory: 10.0M CGroup: /system.slice/nginx.service ├─1234 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; └─1235 nginx: worker process nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
⚠️

Common Pitfalls

Common mistakes when checking Nginx status include:

  • Running systemctl status nginx without sudo, which may not show full details.
  • Confusing nginx -t output with service status; it only checks configuration syntax.
  • Not having Nginx installed or the service named differently on some systems.
bash
systemctl status nginx
# May show limited info without sudo

sudo nginx -t
# Only tests config, does not show if service is running
📊

Quick Reference

Summary of commands to check Nginx status:

CommandPurpose
systemctl status nginxCheck if Nginx service is running or stopped
nginx -tTest Nginx configuration syntax for errors
ps aux | grep nginxSee running Nginx processes
service nginx statusAlternative to systemctl on older systems

Key Takeaways

Use sudo systemctl status nginx to see if Nginx is running.
Run nginx -t to check if the configuration is valid.
Always use sudo for full status details on most systems.
Remember nginx -t does not show service running status.
Check process list with ps aux | grep nginx if needed.