Step-by-Step Guide to Compile, Install, and Configure Nginx on CentOS 7

This tutorial walks through preparing a CentOS 7.5 host, installing required dependencies, creating an nginx user, downloading the source, compiling and installing Nginx 1.11.1, configuring the firewall, and using common Nginx commands to start, test, reload, and enable the service at boot.

Open Source Linux
Open Source Linux
Open Source Linux
Step-by-Step Guide to Compile, Install, and Configure Nginx on CentOS 7

Introduction

After covering basic Nginx concepts, this guide walks through compiling, installing, and configuring Nginx 1.11.1 on a CentOS 7.5 machine.

Preparation

A Linux host (CentOS 7.5).

Download the Nginx source package from the official site.

Install Dependencies

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

Verify installation with rpm -qa.

Create Nginx User

useradd -M -s /sbin/nologin nginx

Download and Extract Source

wget http://nginx.org/download/nginx-1.11.1.tar.gz
tar -xf nginx-1.11.1.tar.gz -C /usr/src

Compile and Install

# step 1: extract (already done)
cd /usr/src/nginx-1.11.1/
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx
make -j 4 && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

Start Nginx

Run /usr/local/nginx/sbin/nginx and open a browser at http://<em>your‑IP</em> to confirm the default page.

Firewall Configuration

If the page is not reachable, either disable the firewall or open port 80:

systemctl stop firewalld && systemctl disable firewalld
firewall-cmd --add-service=http --permanent
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload

Nginx Common Commands

cd /usr/local/nginx/sbin
./nginx -v            # show version
./nginx -t            # test configuration
./nginx               # start
ps -aux | grep nginx  # verify process
./nginx -s reload     # graceful reload
./nginx -s stop       # stop
echo "/usr/local/nginx/sbin/nginx &" >> /etc/rc.local   # enable at boot
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.

Backend DevelopmentCompilationLinuxNginxInstallationCentOS
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

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.