Operations 16 min read

Master Nginx: From Beginner to Ops Pro with Installation, Configuration, and Process Management

This comprehensive guide explains what Nginx is, its advantages over Apache, default configuration paths, step‑by‑step YUM and source installation, service management via init.d and systemd, process architecture, and essential command‑line controls for starting, stopping, reloading, and upgrading the server.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Nginx: From Beginner to Ops Pro with Installation, Configuration, and Process Management

From Nginx Beginner to Operations Expert: Installation, Configuration, and Process Management

What is Nginx?

Nginx is a lightweight, high‑performance reverse‑proxy web server supporting HTTP, HTTPS, SMTP, POP3 and IMAP. It can handle 20‑30 k concurrent connections, with official tests up to 50 k, and is used by many Chinese sites such as Sina, NetEase, and Tencent.

Other web server software

Tomcat : Java servlet/JSP container.

IIS : Windows web server integrated with ASP.NET.

Nginx Advantages

Cross‑platform, simple configuration.

Non‑blocking, high‑concurrency handling.

Low memory consumption (10 workers ≈ 150 MB).

Low cost and open source.

High stability.

Built‑in health‑check.

Nginx Use Cases

HTTP server / static file hosting.

Virtual hosting.

Reverse proxy and load balancing.

API gateway and security management.

Nginx vs Apache

Apache : multi‑process/thread model, higher resource usage.

Nginx : single‑thread asynchronous non‑blocking, lower CPU/memory per request.

Lightweight.

Better static resource performance.

Reverse‑proxy acceleration.

Performance not dependent on high‑end hardware.

Hot deployment support.

Asynchronous handling.

Modular design.

High concurrency performance.

Simple configuration.

Default Configuration File Paths (RHEL/CentOS)

Main config: /etc/nginx/nginx.conf Site configs directory: /etc/nginx/conf.d/ Default site config: /etc/nginx/conf.d/default.conf Web root: /usr/share/nginx/html/ Access log: /var/log/nginx/access.log Error log:

/var/log/nginx/error.log

Nginx Service Installation via YUM

Add official repository:

# nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

Start the service:

systemctl start nginx
netstat -lntp | grep nginx

Check version:

nginx -v

Compile‑Install Nginx from Source

1. Disable firewall and upload package

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
# upload nginx-1.12.0.tar.gz to /opt

2. Install dependencies

yum -y install pcre-devel zlib-devel openssl-devel gcc gcc-c++ make

3. Create nginx user

useradd -M -s /sbin/nologin nginx

4. Compile and install

cd /opt
tar zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx

5. Manage Nginx Service

Test configuration: nginx -t Start: /usr/local/nginx/sbin/nginx or nginx -g "daemon off;" Stop: kill -3 <PID> or nginx -s quit Reload configuration: nginx -s reload or kill -HUP <PID> Log rotation: kill -USR1 <PID> Graceful upgrade:

kill -USR2 <PID>

6. Add System Service (init.d)

#!/bin/bash
#chkconfig: - 99 20
#description: Nginx Service Control Script
COM="/usr/local/nginx/sbin/nginx"
PID="/usr/local/nginx/logs/nginx.pid"
case "$1" in
  start) $COM ;;
  stop) kill -s QUIT $(cat $PID) ;;
  restart) $0 stop ; $0 start ;;
  reload) kill -s HUP $(cat $PID) ;;
  *) echo "Usage: $0 {start|stop|restart|reload}"; exit 1 ;;
esac
exit 0

Make executable and add to startup:

chmod +x /etc/init.d/nginx
chkconfig --add nginx

7. Add Systemd Service

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Enable and start:

chmod 754 /lib/systemd/system/nginx.service
systemctl start nginx.service
systemctl enable nginx.service

Nginx Processes

Two main processes: the master process manages worker processes and loads configuration, while worker processes handle client connections.

ps -elf | grep nginx
# shows master and worker processes

Nginx Command Management

Start: nginx (daemon) or nginx -g "daemon off;" (foreground).

Stop gracefully: nginx -s quit or kill -3 <PID>.

Reload configuration: nginx -s reload or kill -HUP <PID>.

Check syntax: nginx -t.

Log rotation: kill -USR1 <PID>.

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.

process managementNGINXInstallationServer Administration
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.