How to Compile and Install Nginx from Source on Linux

This guide explains key concepts of open source, compilation, and executables, then details the configure‑make‑install workflow and provides a step‑by‑step tutorial for compiling, installing, configuring, and testing Nginx from source on a Linux system.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Compile and Install Nginx from Source on Linux

1. Key Concepts

Open source : source code written in a human‑readable programming language, not directly executable by a computer.

Compilation : translating source code into machine‑readable language.

Executable program : the binary file produced after compilation that can be run.

2. Steps to Compile a Source Program

configure : detects the environment and generates a Makefile. It checks for a suitable compiler, required libraries, OS support, and kernel header files.

Typical usage: ./configure --help – display help.

Common options include installation paths ( --prefix=/path/to/…, --sysconfdir=/path/to/…), enabling or disabling features ( --enable‑FEATURE, --disable‑FEATURE), and specifying dependencies ( --with‑FUNCTION[=…], --without‑FUNCTION).

make : builds the source according to the generated Makefile.

make install : installs the compiled software.

3. Compiling and Installing Nginx

Prerequisite: gcc must be installed.

1. Check the build environment

Key configure options: --prefix: installation directory for Nginx. --conf-path: location of the main configuration file. --with-pcre: path to the PCRE source package. --with-zlib: path to the zlib source package.

2. Compile (invoke gcc)

3. Install

4. Start Nginx

Test with a browser.

5. Post‑installation configuration

1) Make the binary runnable without a full path by creating /etc/profile.d/nginx.sh with appropriate export statements.

2) Simulate a man page by adding a line to /etc/man.config pointing to /usr/local/nginx/man.

3) Simulate library export by creating /etc/ld.so.conf.d/nginx.conf and running ldconfig.

4) Simulate header export by linking the include directory:

ln -sv /usr/local/nginx/include /usr/include/nginx
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.

BackendCompilationConfigurationNGINXInstallation
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.