Master Nginx: From Installation to Advanced Configuration on CentOS
This comprehensive guide explains what Nginx is, why it outperforms Apache, and walks you through installing, compiling, configuring, and running Nginx on CentOS, including essential directives, load‑balancing features, and common command‑line operations.
Nginx is a lightweight web server, reverse proxy, and mail (IMAP/POP3) proxy released under a BSD‑like license. It uses little memory, handles high concurrency, and powers major Chinese sites such as Baidu, JD, Sina, NetEase, Tencent, and Taobao.
Why use Nginx?
Compared with Apache, Nginx consumes fewer resources, supports many more concurrent connections, and is favored by virtual‑host providers. It can handle up to 50,000 concurrent connections, uses epoll/kqueue, and serves as an efficient load‑balancer and HTTP proxy.
Key differences
Apache uses a synchronous multi‑process model (one process per connection); Nginx uses an asynchronous event‑driven model allowing thousands of connections per process.
Apache excels at dynamic content; Nginx excels at static content with lower CPU and memory usage.
Basic usage
System platform: CentOS 6.6 (64‑bit).
Installation Steps
1. Install build tools and libraries
Install PCRE (required for rewrite support) from
http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz, then extract and compile.
2. Install Nginx
Download Nginx source http://nginx.org/download/nginx-1.6.2.tar.gz, extract, enter the directory, and run ./configure && make && make install. Verify the installation with nginx -v.
Configuration
Create a system user for Nginx: useradd -r -s /sbin/nologin www Replace /usr/local/webserver/nginx/conf/nginx.conf with the appropriate configuration (see image). Test the configuration with nginx -t.
Starting Nginx
Start the server using: nginx Verify by accessing the server IP in a browser.
Common Directives
1. Main (global) configuration
worker_processes 2– number of worker processes (often set to CPU cores). worker_cpu_affinity – bind workers to specific CPUs for performance. worker_connections 2048 – max connections per worker. worker_rlimit_nofile 10240 – limit on open file descriptors. use epoll – high‑efficiency event model on Linux.
2. HTTP server
sendfile on– enable zero‑copy file transmission. keepalive_timeout 65 – timeout for persistent connections. client_max_body_size 10m – maximum upload size.
3. Server (virtual host)
listen 80– port to listen on. server_name example.com – host name.
4. Location
root /var/www/html– document root. index index.html index.htm – default index files. proxy_pass http://backend – forward requests to upstream servers.
Additional Features
Access control with allow / deny, directory listing via autoindex on, and gzip compression settings ( gzip on, gzip_min_length 1k, etc.) are also covered.
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.
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.
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.
