How to Install and Configure Nginx with HTTPS on CentOS
This guide explains how to use Nginx as an HTTPS reverse proxy for WeChat mini‑programs, covering kernel requirements, downloading the proper version, compiling with necessary modules, starting the server, configuring nginx.conf, and setting up rate limiting, all on a CentOS system.
Preface
WeChat mini‑programs require HTTPS, but existing online configurations cannot be changed, so the simplest solution is to use Nginx as a reverse proxy that terminates HTTPS and forwards traffic to the internal server. A 4‑core, 16 GB machine can comfortably handle millions of page views per day.
Fundamentals
Nginx relies on the epoll model, which requires a Linux kernel version 2.6 or higher. You can check the kernel version with uname -a. For example, CentOS 6.5 reports:
Download
The official Nginx download page ( http://nginx.org/en/download.html ) offers three version types:
Mainline version – the current development branch.
Stable version – the latest stable release recommended for production.
Legacy versions – older stable releases.
Compile and Install
Nginx depends on several libraries:
gzip module – requires zlib and its development package.
rewrite module – requires pcre and its development package.
SSL support – requires openssl, its development package, and a C++ compiler ( gcc‑c++).
Check for missing modules (e.g., gzip) and install them with yum install zlib zlib-devel if needed.
Typical compilation steps: tar zxvf nginx-1.10.2.tar.gz Enter the extracted directory and run: ./configure --with-http_ssl_module The configure script checks the environment and prints the default installation paths and configuration summary (illustrated in the following image):
After configuration, compile and install:
make make installStart
Before starting Nginx, ensure port 80 is free (e.g., fuser -n tcp 80 or netstat -pan | grep :80). Then start Nginx from the default directory /usr/local/nginx and visit http://<em>ip</em>:80/ to see the welcome page.
Nginx Configuration
The main configuration file nginx.conf resides in /usr/local/nginx/conf. It defines global settings such as logging, which can be overridden by specific modules. The file’s structure is illustrated below:
Top‑level log configuration applies globally, but child modules may override it, as shown in the following snippet:
Rate Limiting
Nginx’s ngx_http_limit_req_module can limit request rates. Configure the burst parameter to define how many requests can be processed in a short burst; a value of 0 blocks traffic. After configuring the module in the http block, remember to include it in the relevant server block.
Example Configuration
An example of a complete Nginx configuration with HTTPS and rate limiting is shown below:
For a detailed configuration reference, see http://www.cszhi.com/20120513/nginx_nginx-conf.html .
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.
