How to Compile and Configure Nginx with HTTPS on Linux – A Step‑By‑Step Guide
This guide explains why and how to use Nginx as an HTTPS reverse proxy for WeChat mini‑programs, covering kernel requirements, downloading, compiling with required modules, installation steps, starting the server, core configuration details, enabling SSL, and applying rate‑limiting rules.
Preface
WeChat mini‑programs require HTTPS, and when existing online configuration cannot be changed, the simplest solution is to place an Nginx reverse proxy with HTTPS in front of the internal server. Nginx’s high performance allows a 4‑core 16 GB machine to handle millions of page views per day.
Basic Knowledge
Nginx relies on the epoll I/O model, which requires a Linux kernel version 2.6 or newer. You can check the kernel version with uname -a. (Image showing kernel version output.)
Download
The official Nginx download page offers three version types:
Mainline – the current development branch.
Stable – the latest stable release recommended for production.
Legacy – older stable releases.
Compilation and Installation
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++).
Example: to check whether the gzip module is present, run the appropriate command (image). If missing, install with yum install zlib zlib-devel.
Typical build steps:
tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure
make
make installThe ./configure script checks the local environment and prints the default installation directory and basic configuration (image).
Starting Nginx
Nginx listens on port 80 by default. Before starting, verify the port is free with fuser -n tcp 80 or netstat -pan | grep :80. After confirming, start Nginx and visit http://<em>IP</em>:80/ to see the welcome page (image).
Nginx Configuration
The main configuration file /usr/local/nginx/conf/nginx.conf contains global settings such as log configuration, which can be overridden in sub‑modules (image). You can test the syntax of a modified configuration with nginx -t (image).
A diagram of the configuration file hierarchy is shown (image).
Enabling HTTPS
During compilation, include the SSL module with ./configure --with-http_ssl_module.
Rate Limiting
Nginx’s ngx_http_limit_req_module can be used to limit request rates. After adding the directives in the http block, reference them in the desired server block. The burst parameter defines how many requests can exceed the rate temporarily; a burst of 0 blocks excess traffic (image).
Example Configuration
An example of a complete configuration file is shown (image).
Author: 徐家三少 Source: https://juejin.im/post/58846fceb123db7389d2b70e
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.
