Operations 5 min read

Step‑by‑Step Guide to Install, Configure, and Manage Nginx on CentOS

This tutorial walks you through downloading the Nginx RPM, locating its directories, checking service status, verifying configuration syntax, and using systemctl or service commands to start, stop, reload, or restart Nginx on a CentOS 7 server.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Step‑by‑Step Guide to Install, Configure, and Manage Nginx on CentOS

1. Installation

Download the RPM package, for example

wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.10.0-1.el7.ngx.x86_64.rpm

, then install it with rpm -ivh nginx-1.10.0-1.el7.ngx.x86_64.rpm. If wget is missing, install it via yum -y install wget.

2. Nginx installation directories

Run whereis nginx to locate files. Typical locations are:

Executable: /usr/sbin/nginx

Modules: /usr/lib64/nginx/modules

Configuration: /etc/nginx/

Default site root: /usr/share/nginx/html

Check the main configuration file and running user with ps aux | grep nginx. The main config file is /etc/nginx/nginx.conf, which defines the PID file, error log, access log, and includes additional files from /etc/nginx/conf.d/.

3. Nginx runtime status

Check status using either: systemctl status nginx.service or service nginx status Running state example:

Stopped state example:

4. Check version

nginx -V

5. Nginx processes

List processes: ps aux | grep nginx # view running processes Filter out the grep itself:

ps aux | grep nginx | grep -v grep   # exclude the grep command

Show listening port (80): netstat -antp | grep :80 or netstat -ntlp | grep :80 Stop Nginx by killing its PID, for example kill -QUIT 2072 for a graceful stop, kill -TERM 2132 for a fast stop, or forcefully with killall -9 nginx or pkill -9 nginx.

6. Verify configuration syntax

Method 1: navigate to the sbin directory and run ./nginx -t.

Successful output shows:

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

Method 2: add -t before the -c option in the start command.

7. Restart Nginx

Method 1: run the reload command from the executable directory, e.g., /usr/sbin/nginx -s reload (or the appropriate path for your installation).

Method 2: find the master PID and send a SIGHUP signal: kill -HUP <pid> to trigger a graceful restart.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ConfigurationLinuxNginxInstallationserver managementsystemctl
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.