Master Nginx on CentOS: Install, Configure, and Manage Services Step‑by‑Step
This guide walks you through downloading and installing Nginx on CentOS, locating its directories, checking service status, viewing version, managing processes, testing configuration syntax, and restarting the server, all with clear commands and illustrative screenshots.
1. Installation
Download the RPM package and install it:
wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.10.0-1.el7.ngx.x86_64.rpm rpm -ivh nginx-1.10.0-1.el7.ngx.x86_64.rpmIf wget is missing, install it with yum -y install wget.
2. Nginx installation directories
Executable: /usr/sbin/nginx Modules: /usr/lib64/nginx/modules Configuration files: /etc/nginx/ Default site root: /usr/share/nginx/html Use ps aux | grep nginx to view running processes and identify the main configuration file and user.
Main configuration file: /etc/nginx/nginx.conf PID file: /var/run/nginx.pid Error log: /var/log/nginx/error.log Access log:
/var/log/nginx/access.log3. Check Nginx status
Run either systemctl status nginx.service or service nginx status to see whether the service is running; screenshots illustrate both running and stopped states.
4. View version
Execute nginx -V to display the compiled version and configuration options.
5. Process management
List Nginx processes with ps aux | grep nginx (filter out the grep process). Check listening ports using netstat -antp | grep :80 or netstat -ntlp | grep :80. To stop Nginx, kill the process using commands such as kill -QUIT PID (graceful), kill -TERM PID (fast), or kill -9 PID (force), or use killall -9 nginx / pkill -9 nginx.
6. Verify configuration syntax
Method 1: navigate to the sbin directory and run ./nginx -t.
Method 2: add -t before the -c option in the start command.
7. Restart Nginx
Method 1: run /usr/sbin/nginx -s reload (or the appropriate path) to reload configuration.
Method 2: find the Nginx PID and execute kill -HUP PID to trigger a graceful restart.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
